Merge "Merge "Merge "Merge "DEPTH_STENCIL_OES as tex format requires OES_depth_textur...
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / query_pool / vktQueryPoolStatisticsTests.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Vulkan Statistics Query Tests
22  *//*--------------------------------------------------------------------*/
23
24 #include "vktQueryPoolStatisticsTests.hpp"
25 #include "vktTestCase.hpp"
26
27 #include "vktDrawImageObjectUtil.hpp"
28 #include "vktDrawBufferObjectUtil.hpp"
29 #include "vktDrawCreateInfoUtil.hpp"
30 #include "vkBuilderUtil.hpp"
31 #include "vkRefUtil.hpp"
32 #include "vkPrograms.hpp"
33
34 #include "deMath.h"
35
36 #include "tcuTestLog.hpp"
37 #include "tcuResource.hpp"
38 #include "tcuImageCompare.hpp"
39 #include "vkImageUtil.hpp"
40 #include "tcuCommandLine.hpp"
41 #include "tcuRGBA.hpp"
42
43 namespace vkt
44 {
45 namespace QueryPool
46 {
47 namespace
48 {
49
50 using namespace vk;
51 using namespace Draw;
52
53 //Test parameters
54 enum
55 {
56         WIDTH   = 64,
57         HEIGHT  = 64
58 };
59
60 std::string inputTypeToGLString (const VkPrimitiveTopology& inputType)
61 {
62         switch (inputType)
63         {
64                 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
65                         return "points";
66                 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
67                 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
68                         return "lines";
69                 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
70                 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
71                         return "lines_adjacency";
72                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
73                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
74                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
75                         return "triangles";
76                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
77                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
78                         return "triangles_adjacency";
79                 default:
80                         DE_ASSERT(DE_FALSE);
81                         return "error";
82         }
83 }
84
85 std::string outputTypeToGLString (const VkPrimitiveTopology& outputType)
86 {
87         switch (outputType)
88         {
89                 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
90                         return "points";
91                 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
92                 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
93                 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
94                 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
95                                 return "line_strip";
96                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
97                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
98                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
99                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
100                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
101                         return "triangle_strip";
102                 default:
103                         DE_ASSERT(DE_FALSE);
104                         return "error";
105         }
106 }
107
108 void beginCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
109 {
110         const VkCommandBufferBeginInfo info =
111         {
112                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,            // VkStructureType                                                      sType;
113                 DE_NULL,                                                                                        // const void*                                                          pNext;
114                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,            // VkCommandBufferUsageFlags                            flags;
115                 DE_NULL,                                                                                        // const VkCommandBufferInheritanceInfo*        pInheritanceInfo;
116         };
117         VK_CHECK(vk.beginCommandBuffer(commandBuffer, &info));
118 }
119
120 void beginSecondaryCommandBuffer (const DeviceInterface&                                vk,
121                                                                   const VkCommandBuffer                                 commandBuffer,
122                                                                   const VkQueryPipelineStatisticFlags   queryFlags,
123                                                                   const VkRenderPass                                    renderPass = (VkRenderPass)0u,
124                                                                   const VkFramebuffer                                   framebuffer = (VkFramebuffer)0u,
125                                                                   const VkCommandBufferUsageFlags               bufferUsageFlags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT)
126 {
127         const VkCommandBufferInheritanceInfo    secCmdBufInheritInfo    =
128         {
129                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
130                 DE_NULL,
131                 renderPass,                                     // renderPass
132                 0u,                                                     // subpass
133                 framebuffer,                            // framebuffer
134                 VK_FALSE,                                       // occlusionQueryEnable
135                 (VkQueryControlFlags)0u,        // queryFlags
136                 queryFlags,                                     // pipelineStatistics
137         };
138
139         const VkCommandBufferBeginInfo                  info                                    =
140         {
141                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,    // VkStructureType                                                      sType;
142                 DE_NULL,                                                                                // const void*                                                          pNext;
143                 bufferUsageFlags,                                                               // VkCommandBufferUsageFlags                            flags;
144                 &secCmdBufInheritInfo,                                                  // const VkCommandBufferInheritanceInfo*        pInheritanceInfo;
145         };
146         VK_CHECK(vk.beginCommandBuffer(commandBuffer, &info));
147 }
148
149 void submitCommandsAndWait (const DeviceInterface&      vk,
150                                                         const VkDevice                  device,
151                                                         const VkQueue                   queue,
152                                                         const VkCommandBuffer   commandBuffer)
153 {
154         const VkFenceCreateInfo fenceInfo       =
155         {
156                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,    // VkStructureType              sType;
157                 DE_NULL,                                                                // const void*                  pNext;
158                 (VkFenceCreateFlags)0,                                  // VkFenceCreateFlags   flags;
159         };
160         const Unique<VkFence>   fence           (createFence(vk, device, &fenceInfo));
161
162         const VkSubmitInfo              submitInfo      =
163         {
164                 VK_STRUCTURE_TYPE_SUBMIT_INFO,  // VkStructureType                              sType;
165                 DE_NULL,                                                // const void*                                  pNext;
166                 0u,                                                             // uint32_t                                             waitSemaphoreCount;
167                 DE_NULL,                                                // const VkSemaphore*                   pWaitSemaphores;
168                 DE_NULL,                                                // const VkPipelineStageFlags*  pWaitDstStageMask;
169                 1u,                                                             // uint32_t                                             commandBufferCount;
170                 &commandBuffer,                                 // const VkCommandBuffer*               pCommandBuffers;
171                 0u,                                                             // uint32_t                                             signalSemaphoreCount;
172                 DE_NULL,                                                // const VkSemaphore*                   pSignalSemaphores;
173         };
174         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
175         VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));
176 }
177
178 Move<VkQueryPool> makeQueryPool (const DeviceInterface& vk, const VkDevice device, VkQueryPipelineStatisticFlags statisticFlags)
179 {
180         const VkQueryPoolCreateInfo queryPoolCreateInfo =
181         {
182                 VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,       // VkStructureType                                      sType
183                 DE_NULL,                                                                        // const void*                                          pNext
184                 (VkQueryPoolCreateFlags)0,                                      // VkQueryPoolCreateFlags                       flags
185                 VK_QUERY_TYPE_PIPELINE_STATISTICS ,                     // VkQueryType                                          queryType
186                 1u,                                                                                     // deUint32                                                     entryCount
187                 statisticFlags,                                                         // VkQueryPipelineStatisticFlags        pipelineStatistics
188         };
189         return createQueryPool(vk, device, &queryPoolCreateInfo);
190 }
191
192 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk, const VkDevice device, const VkDescriptorSetLayout* descriptorSetLayout)
193 {
194         const VkPipelineLayoutCreateInfo pipelineLayoutParams =
195         {
196                 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,  // VkStructureType                                      sType;
197                 DE_NULL,                                                                                // const void*                                          pNext;
198                 0u,                                                                                             // VkPipelineLayoutCreateFlags          flags;
199                 1u,                                                                                             // deUint32                                                     setLayoutCount;
200                 descriptorSetLayout,                                                    // const VkDescriptorSetLayout*         pSetLayouts;
201                 0u,                                                                                             // deUint32                                                     pushConstantRangeCount;
202                 DE_NULL,                                                                                // const VkPushConstantRange*           pPushConstantRanges;
203         };
204         return (createPipelineLayout(vk, device, &pipelineLayoutParams));
205 }
206
207 void clearBuffer (const DeviceInterface& vk, const VkDevice device, const de::SharedPtr<Buffer> buffer, const VkDeviceSize bufferSizeBytes)
208 {
209         const std::vector<deUint8>      data                    ((size_t)bufferSizeBytes, 0u);
210         const Allocation&                       allocation              = buffer->getBoundMemory();
211         void*                                           allocationData  = allocation.getHostPtr();
212         invalidateMappedMemoryRange(vk, device, allocation.getMemory(), allocation.getOffset(), bufferSizeBytes);
213         deMemcpy(allocationData, &data[0], (size_t)bufferSizeBytes);
214 }
215
216 class StatisticQueryTestInstance : public TestInstance
217 {
218 public:
219                                         StatisticQueryTestInstance      (Context& context);
220 protected:
221         virtual void    checkExtensions                         (void);
222 };
223
224 StatisticQueryTestInstance::StatisticQueryTestInstance (Context& context)
225         : TestInstance  (context)
226 {
227 }
228
229 void StatisticQueryTestInstance::checkExtensions (void)
230 {
231         if (!m_context.getDeviceFeatures().pipelineStatisticsQuery)
232                 throw tcu::NotSupportedError("Pipeline statistics queries are not supported");
233 }
234
235 class ComputeInvocationsTestInstance : public StatisticQueryTestInstance
236 {
237 public:
238         struct ParametersCompute
239         {
240                 tcu::UVec3      localSize;
241                 tcu::UVec3      groupSize;
242                 std::string     shaderName;
243         };
244                                                         ComputeInvocationsTestInstance          (Context& context, const std::vector<ParametersCompute>& parameters);
245         tcu::TestStatus                 iterate                                                         (void);
246 protected:
247         virtual tcu::TestStatus executeTest                                                     (const VkCommandPool&                   cmdPool,
248                                                                                                                                  const VkPipelineLayout                 pipelineLayout,
249                                                                                                                                  const VkDescriptorSet&                 descriptorSet,
250                                                                                                                                  const de::SharedPtr<Buffer>    buffer,
251                                                                                                                                  const VkDeviceSize                             bufferSizeBytes);
252         deUint32                                getComputeExecution                                     (const ParametersCompute& parm) const
253                 {
254                         return parm.localSize.x() * parm.localSize.y() *parm.localSize.z() * parm.groupSize.x() * parm.groupSize.y() * parm.groupSize.z();
255                 }
256         const std::vector<ParametersCompute>&   m_parameters;
257 };
258
259 ComputeInvocationsTestInstance::ComputeInvocationsTestInstance (Context& context, const std::vector<ParametersCompute>& parameters)
260         : StatisticQueryTestInstance    (context)
261         , m_parameters                                  (parameters)
262 {
263 }
264
265 tcu::TestStatus ComputeInvocationsTestInstance::iterate (void)
266 {
267         checkExtensions();
268         const DeviceInterface&                          vk                                              = m_context.getDeviceInterface();
269         const VkDevice                                          device                                  = m_context.getDevice();
270         deUint32                                                        maxSize                                 = 0u;
271
272         for(size_t parametersNdx = 0; parametersNdx < m_parameters.size(); ++parametersNdx)
273                 maxSize = deMaxu32(maxSize, getComputeExecution(m_parameters[parametersNdx]));
274
275         const VkDeviceSize                                      bufferSizeBytes                 = static_cast<VkDeviceSize>(deAlignSize(static_cast<size_t>(sizeof(deUint32) * maxSize),
276                                                                                                                                                                                                 static_cast<size_t>(m_context.getDeviceProperties().limits.nonCoherentAtomSize)));
277         de::SharedPtr<Buffer>                           buffer                                  = Buffer::createAndAlloc(vk, device, BufferCreateInfo(bufferSizeBytes, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT),
278                                                                                                                                                                                          m_context.getDefaultAllocator(), MemoryRequirement::HostVisible);
279
280         const Unique<VkDescriptorSetLayout>     descriptorSetLayout             (DescriptorSetLayoutBuilder()
281                         .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT)
282                         .build(vk, device));
283
284         const Unique<VkPipelineLayout>          pipelineLayout                  (makePipelineLayout(vk, device, &(*descriptorSetLayout)));
285
286         const Unique<VkDescriptorPool>          descriptorPool                  (DescriptorPoolBuilder()
287                         .addType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)
288                         .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u));
289
290         const VkDescriptorSetAllocateInfo allocateParams                =
291         {
292                 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType                              sType;
293                 DE_NULL,                                                                                // const void*                                  pNext;
294                 *descriptorPool,                                                                // VkDescriptorPool                             descriptorPool;
295                 1u,                                                                                             // deUint32                                             setLayoutCount;
296                 &(*descriptorSetLayout),                                                // const VkDescriptorSetLayout* pSetLayouts;
297         };
298
299         const Unique<VkDescriptorSet>           descriptorSet           (allocateDescriptorSet(vk, device, &allocateParams));
300         const VkDescriptorBufferInfo            descriptorInfo          =
301         {
302                 buffer->object(),       //VkBuffer              buffer;
303                 0ull,                           //VkDeviceSize  offset;
304                 bufferSizeBytes,        //VkDeviceSize  range;
305         };
306
307         DescriptorSetUpdateBuilder()
308                 .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &descriptorInfo)
309                 .update(vk, device);
310
311         const CmdPoolCreateInfo                 cmdPoolCreateInfo       (m_context.getUniversalQueueFamilyIndex());
312         const Unique<VkCommandPool>             cmdPool                         (createCommandPool(vk, device, &cmdPoolCreateInfo));
313
314         return executeTest (*cmdPool, *pipelineLayout, *descriptorSet, buffer, bufferSizeBytes);
315 }
316
317 tcu::TestStatus ComputeInvocationsTestInstance::executeTest (const VkCommandPool&                       cmdPool,
318                                                                                                                          const VkPipelineLayout                 pipelineLayout,
319                                                                                                                          const VkDescriptorSet&                 descriptorSet,
320                                                                                                                          const de::SharedPtr<Buffer>    buffer,
321                                                                                                                          const VkDeviceSize                             bufferSizeBytes)
322 {
323         const DeviceInterface&                          vk                                              = m_context.getDeviceInterface();
324         const VkDevice                                          device                                  = m_context.getDevice();
325         const VkQueue                                           queue                                   = m_context.getUniversalQueue();
326         const VkBufferMemoryBarrier                     computeFinishBarrier    =
327         {
328                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
329                 DE_NULL,                                                                        // const void*          pNext;
330                 VK_ACCESS_SHADER_WRITE_BIT,                                     // VkAccessFlags        srcAccessMask;
331                 VK_ACCESS_HOST_READ_BIT,                                        // VkAccessFlags        dstAccessMask;
332                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
333                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     destQueueFamilyIndex;
334                 buffer->object(),                                                       // VkBuffer                     buffer;
335                 0ull,                                                                           // VkDeviceSize         offset;
336                 bufferSizeBytes,                                                        // VkDeviceSize         size;
337         };
338
339         for(size_t parametersNdx = 0u; parametersNdx < m_parameters.size(); ++parametersNdx)
340         {
341                 clearBuffer(vk, device, buffer, bufferSizeBytes);
342                 const Unique<VkShaderModule>                    shaderModule                            (createShaderModule(vk, device,
343                                                                                                                                                         m_context.getBinaryCollection().get(m_parameters[parametersNdx].shaderName), (VkShaderModuleCreateFlags)0u));
344
345                 const VkPipelineShaderStageCreateInfo   pipelineShaderStageParams       =
346                 {
347                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // VkStructureType                                              sType;
348                         DE_NULL,                                                                                                // const void*                                                  pNext;
349                         (VkPipelineShaderStageCreateFlags)0u,                                   // VkPipelineShaderStageCreateFlags             flags;
350                         VK_SHADER_STAGE_COMPUTE_BIT,                                                    // VkShaderStageFlagBits                                stage;
351                         *shaderModule,                                                                                  // VkShaderModule                                               module;
352                         "main",                                                                                                 // const char*                                                  pName;
353                         DE_NULL,                                                                                                // const VkSpecializationInfo*                  pSpecializationInfo;
354                 };
355
356                 const VkComputePipelineCreateInfo               pipelineCreateInfo                      =
357                 {
358                         VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType                                      sType;
359                         DE_NULL,                                                                                // const void*                                          pNext;
360                         (VkPipelineCreateFlags)0u,                                              // VkPipelineCreateFlags                        flags;
361                         pipelineShaderStageParams,                                              // VkPipelineShaderStageCreateInfo      stage;
362                         pipelineLayout,                                                                 // VkPipelineLayout                                     layout;
363                         DE_NULL,                                                                                // VkPipeline                                           basePipelineHandle;
364                         0,                                                                                              // deInt32                                                      basePipelineIndex;
365                 };
366                 const Unique<VkPipeline> pipeline(createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo));
367
368                 const Unique<VkCommandBuffer>   cmdBuffer                       (allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
369                 const Unique<VkQueryPool>               queryPool                       (makeQueryPool(vk, device, VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT));
370
371                 beginCommandBuffer(vk, *cmdBuffer);
372                         vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, 1u);
373
374                         vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
375                         vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
376
377                         vk.cmdBeginQuery(*cmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
378                         vk.cmdDispatch(*cmdBuffer, m_parameters[parametersNdx].groupSize.x(), m_parameters[parametersNdx].groupSize.y(), m_parameters[parametersNdx].groupSize.z());
379                         vk.cmdEndQuery(*cmdBuffer, *queryPool, 0u);
380
381                         vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT,
382                                 (VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeFinishBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
383                 VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
384
385                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Compute shader invocations: " << getComputeExecution(m_parameters[parametersNdx]) << tcu::TestLog::EndMessage;
386
387                 // Wait for completion
388                 submitCommandsAndWait(vk, device, queue, *cmdBuffer);
389
390                 // Validate the results
391                 const Allocation& bufferAllocation = buffer->getBoundMemory();
392                 invalidateMappedMemoryRange(vk, device, bufferAllocation.getMemory(), bufferAllocation.getOffset(), bufferSizeBytes);
393
394                 {
395                         deUint64 data = 0u;
396                         VK_CHECK(vk.getQueryPoolResults(device, *queryPool, 0u, 1u, sizeof(deUint64), &data, 0u, VK_QUERY_RESULT_64_BIT));
397                         if (getComputeExecution(m_parameters[parametersNdx]) != data)
398                                 return tcu::TestStatus::fail("QueryPoolResults incorrect");
399                 }
400
401                 const deUint32* bufferPtr = static_cast<deUint32*>(bufferAllocation.getHostPtr());
402                 for (deUint32 ndx = 0u; ndx < getComputeExecution(m_parameters[parametersNdx]); ++ndx)
403                 {
404                         if (bufferPtr[ndx] != ndx)
405                                 return tcu::TestStatus::fail("Compute shader didn't write data to the buffer");
406                 }
407         }
408         return tcu::TestStatus::pass("Pass");
409 }
410
411 class ComputeInvocationsSecondaryTestInstance : public ComputeInvocationsTestInstance
412 {
413 public:
414                                                         ComputeInvocationsSecondaryTestInstance (Context& context, const std::vector<ParametersCompute>& parameters);
415 protected:
416         tcu::TestStatus                 executeTest                                                             (const VkCommandPool&                   cmdPool,
417                                                                                                                                          const VkPipelineLayout                 pipelineLayout,
418                                                                                                                                          const VkDescriptorSet&                 descriptorSet,
419                                                                                                                                          const de::SharedPtr<Buffer>    buffer,
420                                                                                                                                          const VkDeviceSize                             bufferSizeBytes);
421         virtual tcu::TestStatus checkResult                                                             (const de::SharedPtr<Buffer>    buffer,
422                                                                                                                                          const VkDeviceSize                             bufferSizeBytes,
423                                                                                                                                          const VkQueryPool                              queryPool);
424 };
425
426 ComputeInvocationsSecondaryTestInstance::ComputeInvocationsSecondaryTestInstance        (Context& context, const std::vector<ParametersCompute>& parameters)
427         : ComputeInvocationsTestInstance        (context, parameters)
428 {
429 }
430
431 tcu::TestStatus ComputeInvocationsSecondaryTestInstance::executeTest (const VkCommandPool&                      cmdPool,
432                                                                                                                                           const VkPipelineLayout                pipelineLayout,
433                                                                                                                                           const VkDescriptorSet&                descriptorSet,
434                                                                                                                                           const de::SharedPtr<Buffer>   buffer,
435                                                                                                                                           const VkDeviceSize                    bufferSizeBytes)
436 {
437         typedef de::SharedPtr<Unique<VkShaderModule> >  VkShaderModuleSp;
438         typedef de::SharedPtr<Unique<VkPipeline> >              VkPipelineSp;
439
440         const DeviceInterface&                                  vk                                                      = m_context.getDeviceInterface();
441         const VkDevice                                                  device                                          = m_context.getDevice();
442         const VkQueue                                                   queue                                           = m_context.getUniversalQueue();
443
444         const VkBufferMemoryBarrier                             computeShaderWriteBarrier       =
445         {
446                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
447                 DE_NULL,                                                                        // const void*          pNext;
448                 VK_ACCESS_SHADER_WRITE_BIT,                                     // VkAccessFlags        srcAccessMask;
449                 VK_ACCESS_SHADER_WRITE_BIT,                                     // VkAccessFlags        dstAccessMask;
450                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
451                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     destQueueFamilyIndex;
452                 buffer->object(),                                                       // VkBuffer                     buffer;
453                 0ull,                                                                           // VkDeviceSize         offset;
454                 bufferSizeBytes,                                                        // VkDeviceSize         size;
455         };
456
457         const VkBufferMemoryBarrier                             computeFinishBarrier            =
458         {
459                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
460                 DE_NULL,                                                                        // const void*          pNext;
461                 VK_ACCESS_SHADER_WRITE_BIT,                                     // VkAccessFlags        srcAccessMask;
462                 VK_ACCESS_HOST_READ_BIT,                                        // VkAccessFlags        dstAccessMask;
463                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
464                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     destQueueFamilyIndex;
465                 buffer->object(),                                                       // VkBuffer                     buffer;
466                 0ull,                                                                           // VkDeviceSize         offset;
467                 bufferSizeBytes,                                                        // VkDeviceSize         size;
468         };
469
470         std::vector<VkShaderModuleSp>                   shaderModule;
471         std::vector<VkPipelineSp>                               pipeline;
472         for(size_t parametersNdx = 0; parametersNdx < m_parameters.size(); ++parametersNdx)
473         {
474                 shaderModule.push_back(VkShaderModuleSp(new Unique<VkShaderModule>(createShaderModule(vk, device, m_context.getBinaryCollection().get(m_parameters[parametersNdx].shaderName), (VkShaderModuleCreateFlags)0u))));
475                 const VkPipelineShaderStageCreateInfo   pipelineShaderStageParams       =
476                 {
477                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // VkStructureType                                              sType;
478                         DE_NULL,                                                                                                // const void*                                                  pNext;
479                         0u,                                                                                                             // VkPipelineShaderStageCreateFlags             flags;
480                         VK_SHADER_STAGE_COMPUTE_BIT,                                                    // VkShaderStageFlagBits                                stage;
481                         shaderModule.back().get()->get(),                                               // VkShaderModule                                               module;
482                         "main",                                                                                                 // const char*                                                  pName;
483                         DE_NULL,                                                                                                // const VkSpecializationInfo*                  pSpecializationInfo;
484                 };
485
486                 const VkComputePipelineCreateInfo               pipelineCreateInfo                      =
487                 {
488                         VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType                                      sType;
489                         DE_NULL,                                                                                // const void*                                          pNext;
490                         0u,                                                                                             // VkPipelineCreateFlags                        flags;
491                         pipelineShaderStageParams,                                              // VkPipelineShaderStageCreateInfo      stage;
492                         pipelineLayout,                                                                 // VkPipelineLayout                                     layout;
493                         DE_NULL,                                                                                // VkPipeline                                           basePipelineHandle;
494                         0,                                                                                              // deInt32                                                      basePipelineIndex;
495                 };
496                 pipeline.push_back(VkPipelineSp(new Unique<VkPipeline>(createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo))));
497         }
498
499         const Unique<VkCommandBuffer>                           primaryCmdBuffer                        (allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
500         const Unique<VkCommandBuffer>                           secondaryCmdBuffer                      (allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY));
501
502         const Unique<VkQueryPool>                                       queryPool                                       (makeQueryPool(vk, device, VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT));
503
504         clearBuffer(vk, device, buffer, bufferSizeBytes);
505         beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT);
506                 vk.cmdBindDescriptorSets(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
507                 vk.cmdResetQueryPool(*secondaryCmdBuffer, *queryPool, 0u, 1u);
508                 vk.cmdBeginQuery(*secondaryCmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
509                 for(size_t parametersNdx = 0; parametersNdx < m_parameters.size(); ++parametersNdx)
510                 {
511                                 vk.cmdBindPipeline(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline[parametersNdx].get()->get());
512                                 vk.cmdDispatch(*secondaryCmdBuffer, m_parameters[parametersNdx].groupSize.x(), m_parameters[parametersNdx].groupSize.y(), m_parameters[parametersNdx].groupSize.z());
513
514                                 vk.cmdPipelineBarrier(*secondaryCmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
515                                         (VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeShaderWriteBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
516                 }
517                 vk.cmdEndQuery(*secondaryCmdBuffer, *queryPool, 0u);
518         VK_CHECK(vk.endCommandBuffer(*secondaryCmdBuffer));
519
520         beginCommandBuffer(vk, *primaryCmdBuffer);
521                 vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &secondaryCmdBuffer.get());
522
523                 vk.cmdPipelineBarrier(*primaryCmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT,
524                         (VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeFinishBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
525
526         VK_CHECK(vk.endCommandBuffer(*primaryCmdBuffer));
527
528         // Wait for completion
529         submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
530         return checkResult(buffer, bufferSizeBytes, *queryPool);
531 }
532
533 tcu::TestStatus ComputeInvocationsSecondaryTestInstance::checkResult (const de::SharedPtr<Buffer> buffer, const VkDeviceSize bufferSizeBytes, const VkQueryPool queryPool)
534 {
535         const DeviceInterface&  vk                                      = m_context.getDeviceInterface();
536         const VkDevice                  device                          = m_context.getDevice();
537         {
538                 deUint64 result         = 0u;
539                 deUint64 expected       = 0u;
540                 for(size_t parametersNdx = 0; parametersNdx < m_parameters.size(); ++parametersNdx)
541                         expected += getComputeExecution(m_parameters[parametersNdx]);
542                 VK_CHECK(vk.getQueryPoolResults(device, queryPool, 0u, 1u, sizeof(deUint64), &result, 0u, VK_QUERY_RESULT_64_BIT));
543                 if (expected != result)
544                         return tcu::TestStatus::fail("QueryPoolResults incorrect");
545         }
546
547         {
548                 // Validate the results
549                 const Allocation&       bufferAllocation        = buffer->getBoundMemory();
550                 invalidateMappedMemoryRange(vk, device, bufferAllocation.getMemory(), bufferAllocation.getOffset(), bufferSizeBytes);
551                 const deUint32*         bufferPtr                       = static_cast<deUint32*>(bufferAllocation.getHostPtr());
552                 deUint32                        minSize                         = ~0u;
553                 for(size_t parametersNdx = 0; parametersNdx < m_parameters.size(); ++parametersNdx)
554                         minSize = deMinu32(minSize, getComputeExecution(m_parameters[parametersNdx]));
555                 for (deUint32 ndx = 0u; ndx < minSize; ++ndx)
556                 {
557                         if (bufferPtr[ndx] != ndx * m_parameters.size())
558                                 return tcu::TestStatus::fail("Compute shader didn't write data to the buffer");
559                 }
560         }
561         return tcu::TestStatus::pass("Pass");
562 }
563
564 class ComputeInvocationsSecondaryInheritedTestInstance : public ComputeInvocationsSecondaryTestInstance
565 {
566 public:
567                                         ComputeInvocationsSecondaryInheritedTestInstance        (Context& context, const std::vector<ParametersCompute>& parameters);
568 protected:
569         virtual void    checkExtensions                                                 (void);
570         tcu::TestStatus executeTest                                                             (const VkCommandPool&                   cmdPool,
571                                                                                                                          const VkPipelineLayout                 pipelineLayout,
572                                                                                                                          const VkDescriptorSet&                 descriptorSet,
573                                                                                                                          const de::SharedPtr<Buffer>    buffer,
574                                                                                                                          const VkDeviceSize                             bufferSizeBytes);
575 };
576
577 ComputeInvocationsSecondaryInheritedTestInstance::ComputeInvocationsSecondaryInheritedTestInstance      (Context& context, const std::vector<ParametersCompute>& parameters)
578         : ComputeInvocationsSecondaryTestInstance       (context, parameters)
579 {
580 }
581
582 void ComputeInvocationsSecondaryInheritedTestInstance::checkExtensions (void)
583 {
584         StatisticQueryTestInstance::checkExtensions();
585         if (!m_context.getDeviceFeatures().inheritedQueries)
586                 throw tcu::NotSupportedError("Inherited queries are not supported");
587 }
588
589 tcu::TestStatus ComputeInvocationsSecondaryInheritedTestInstance::executeTest (const VkCommandPool&                     cmdPool,
590                                                                                                                                                           const VkPipelineLayout                pipelineLayout,
591                                                                                                                                                           const VkDescriptorSet&                descriptorSet,
592                                                                                                                                                           const de::SharedPtr<Buffer>   buffer,
593                                                                                                                                                           const VkDeviceSize                    bufferSizeBytes)
594 {
595         typedef de::SharedPtr<Unique<VkShaderModule> >  VkShaderModuleSp;
596         typedef de::SharedPtr<Unique<VkPipeline> >              VkPipelineSp;
597
598         const DeviceInterface&                                          vk                                                              = m_context.getDeviceInterface();
599         const VkDevice                                                          device                                                  = m_context.getDevice();
600         const VkQueue                                                           queue                                                   = m_context.getUniversalQueue();
601
602         const VkBufferMemoryBarrier                                     computeShaderWriteBarrier               =
603         {
604                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
605                 DE_NULL,                                                                        // const void*          pNext;
606                 VK_ACCESS_SHADER_WRITE_BIT,                                     // VkAccessFlags        srcAccessMask;
607                 VK_ACCESS_SHADER_WRITE_BIT,                                     // VkAccessFlags        dstAccessMask;
608                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
609                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     destQueueFamilyIndex;
610                 buffer->object(),                                                       // VkBuffer                     buffer;
611                 0ull,                                                                           // VkDeviceSize         offset;
612                 bufferSizeBytes,                                                        // VkDeviceSize         size;
613         };
614
615         const VkBufferMemoryBarrier                                     computeFinishBarrier                    =
616         {
617                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
618                 DE_NULL,                                                                        // const void*          pNext;
619                 VK_ACCESS_SHADER_WRITE_BIT,                                     // VkAccessFlags        srcAccessMask;
620                 VK_ACCESS_HOST_READ_BIT,                                        // VkAccessFlags        dstAccessMask;
621                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
622                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     destQueueFamilyIndex;
623                 buffer->object(),                                                       // VkBuffer                     buffer;
624                 0ull,                                                                           // VkDeviceSize         offset;
625                 bufferSizeBytes,                                                        // VkDeviceSize         size;
626         };
627
628         std::vector<VkShaderModuleSp>                           shaderModule;
629         std::vector<VkPipelineSp>                                       pipeline;
630         for(size_t parametersNdx = 0u; parametersNdx < m_parameters.size(); ++parametersNdx)
631         {
632                 shaderModule.push_back(VkShaderModuleSp(new Unique<VkShaderModule>(createShaderModule(vk, device, m_context.getBinaryCollection().get(m_parameters[parametersNdx].shaderName), (VkShaderModuleCreateFlags)0u))));
633                 const VkPipelineShaderStageCreateInfo   pipelineShaderStageParams               =
634                 {
635                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // VkStructureType                                      sType;
636                         DE_NULL,                                                                                                // const void*                                          pNext;
637                         0u,                                                                                                             // VkPipelineShaderStageCreateFlags     flags;
638                         VK_SHADER_STAGE_COMPUTE_BIT,                                                    // VkShaderStageFlagBits                        stage;
639                         shaderModule.back().get()->get(),                                               // VkShaderModule                                       module;
640                         "main",                                                                                                 // const char*                                          pName;
641                         DE_NULL,                                                                                                // const VkSpecializationInfo*          pSpecializationInfo;
642                 };
643
644                 const VkComputePipelineCreateInfo               pipelineCreateInfo                              =
645                 {
646                         VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType                                      sType;
647                         DE_NULL,                                                                                // const void*                                          pNext;
648                         0u,                                                                                             // VkPipelineCreateFlags                        flags;
649                         pipelineShaderStageParams,                                              // VkPipelineShaderStageCreateInfo      stage;
650                         pipelineLayout,                                                                 // VkPipelineLayout                                     layout;
651                         DE_NULL,                                                                                // VkPipeline                                           basePipelineHandle;
652                         0,                                                                                              // deInt32                                                      basePipelineIndex;
653                 };
654                 pipeline.push_back(VkPipelineSp(new Unique<VkPipeline>(createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo))));
655         }
656
657         const Unique<VkCommandBuffer>                           primaryCmdBuffer                        (allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
658         const Unique<VkCommandBuffer>                           secondaryCmdBuffer                      (allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY));
659
660         const Unique<VkQueryPool>                                       queryPool                                       (makeQueryPool(vk, device, VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT));
661
662         clearBuffer(vk, device, buffer, bufferSizeBytes);
663         beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT);
664                 vk.cmdBindDescriptorSets(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
665                 for(size_t parametersNdx = 1; parametersNdx < m_parameters.size(); ++parametersNdx)
666                 {
667                                 vk.cmdBindPipeline(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline[parametersNdx].get()->get());
668                                 vk.cmdDispatch(*secondaryCmdBuffer, m_parameters[parametersNdx].groupSize.x(), m_parameters[parametersNdx].groupSize.y(), m_parameters[parametersNdx].groupSize.z());
669
670                                 vk.cmdPipelineBarrier(*secondaryCmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
671                                         (VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeShaderWriteBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
672                 }
673         VK_CHECK(vk.endCommandBuffer(*secondaryCmdBuffer));
674
675         beginCommandBuffer(vk, *primaryCmdBuffer);
676                 vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, 1u);
677                 vk.cmdBindDescriptorSets(*primaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
678                 vk.cmdBindPipeline(*primaryCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline[0].get()->get());
679
680                 vk.cmdBeginQuery(*primaryCmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
681                 vk.cmdDispatch(*primaryCmdBuffer, m_parameters[0].groupSize.x(), m_parameters[0].groupSize.y(), m_parameters[0].groupSize.z());
682
683                 vk.cmdPipelineBarrier(*primaryCmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
684                                 (VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeShaderWriteBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
685
686                 vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &secondaryCmdBuffer.get());
687
688                 vk.cmdPipelineBarrier(*primaryCmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT,
689                         (VkDependencyFlags)0u, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &computeFinishBarrier, 0u, (const VkImageMemoryBarrier*)DE_NULL);
690
691                 vk.cmdEndQuery(*primaryCmdBuffer, *queryPool, 0u);
692         VK_CHECK(vk.endCommandBuffer(*primaryCmdBuffer));
693
694         // Wait for completion
695         submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
696         return checkResult(buffer, bufferSizeBytes, *queryPool);
697 }
698
699 class GraphicBasicTestInstance : public StatisticQueryTestInstance
700 {
701 public:
702         struct VertexData
703         {
704                 VertexData (const tcu::Vec4 position_, const tcu::Vec4 color_)
705                         : position      (position_)
706                         , color         (color_)
707                 {}
708                 tcu::Vec4       position;
709                 tcu::Vec4       color;
710         };
711         struct  ParametersGraphic
712         {
713                         ParametersGraphic (const VkQueryPipelineStatisticFlags queryStatisticFlags_, const VkPrimitiveTopology primitiveTopology_)
714                         : queryStatisticFlags   (queryStatisticFlags_)
715                         , primitiveTopology             (primitiveTopology_)
716                 {}
717                 VkQueryPipelineStatisticFlags   queryStatisticFlags;
718                 VkPrimitiveTopology                             primitiveTopology;
719         };
720                                                                                         GraphicBasicTestInstance                        (vkt::Context&                                  context,
721                                                                                                                                                                  const std::vector<VertexData>& data,
722                                                                                                                                                                  const ParametersGraphic&               parametersGraphic);
723         tcu::TestStatus                                                 iterate                                                         (void);
724 protected:
725         de::SharedPtr<Buffer>                                   creatAndFillVertexBuffer                        (void);
726         virtual void                                                    createPipeline                                          (void) = 0;
727         void                                                                    creatColorAttachmentAndRenderPass       (void);
728         bool                                                                    checkImage                                                      (void);
729         virtual tcu::TestStatus                                 executeTest                                                     (void) = 0;
730         virtual tcu::TestStatus                                 checkResult                                                     (VkQueryPool queryPool) = 0;
731         virtual void                                                    draw                                                            (VkCommandBuffer cmdBuffer) = 0;
732
733         const VkFormat                                          m_colorAttachmentFormat;
734         de::SharedPtr<Image>                            m_colorAttachmentImage;
735         de::SharedPtr<Image>                            m_depthImage;
736         Move<VkImageView>                                       m_attachmentView;
737         Move<VkImageView>                                       m_depthiew;
738         Move<VkRenderPass>                                      m_renderPass;
739         Move<VkFramebuffer>                                     m_framebuffer;
740         Move<VkPipeline>                                        m_pipeline;
741         Move<VkPipelineLayout>                          m_pipelineLayout;
742         const std::vector<VertexData>&          m_data;
743         const ParametersGraphic&                        m_parametersGraphic;
744 };
745
746 GraphicBasicTestInstance::GraphicBasicTestInstance (vkt::Context&                                       context,
747                                                                                                         const std::vector<VertexData>&  data,
748                                                                                                         const ParametersGraphic&                parametersGraphic)
749         : StatisticQueryTestInstance    (context)
750         , m_colorAttachmentFormat               (VK_FORMAT_R8G8B8A8_UNORM)
751         , m_data                                                (data)
752         , m_parametersGraphic                   (parametersGraphic)
753 {
754 }
755
756 tcu::TestStatus GraphicBasicTestInstance::iterate (void)
757 {
758         checkExtensions();
759         creatColorAttachmentAndRenderPass();
760         createPipeline();
761         return executeTest();
762 }
763
764 de::SharedPtr<Buffer> GraphicBasicTestInstance::creatAndFillVertexBuffer (void)
765 {
766         const DeviceInterface&          vk                              = m_context.getDeviceInterface();
767         const VkDevice                          device                  = m_context.getDevice();
768
769         const VkDeviceSize                      dataSize                = static_cast<VkDeviceSize>(deAlignSize(static_cast<size_t>( m_data.size() * sizeof(VertexData)),
770                 static_cast<size_t>(m_context.getDeviceProperties().limits.nonCoherentAtomSize)));
771
772         de::SharedPtr<Buffer>           vertexBuffer    = Buffer::createAndAlloc(vk, device, BufferCreateInfo(dataSize,
773                 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT), m_context.getDefaultAllocator(), MemoryRequirement::HostVisible);
774
775         deUint8*                                        ptr                             = reinterpret_cast<deUint8*>(vertexBuffer->getBoundMemory().getHostPtr());
776         deMemcpy(ptr, &m_data[0], static_cast<size_t>( m_data.size() * sizeof(VertexData)));
777
778         flushMappedMemoryRange(vk, device, vertexBuffer->getBoundMemory().getMemory(), vertexBuffer->getBoundMemory().getOffset(), dataSize);
779         return vertexBuffer;
780 }
781
782 void GraphicBasicTestInstance::creatColorAttachmentAndRenderPass (void)
783 {
784         const DeviceInterface&  vk              = m_context.getDeviceInterface();
785         const VkDevice                  device  = m_context.getDevice();
786
787         {
788                 VkExtent3D                                      imageExtent                             =
789                 {
790                         WIDTH,  // width;
791                         HEIGHT, // height;
792                         1u              // depth;
793                 };
794
795                 const ImageCreateInfo           colorImageCreateInfo    (VK_IMAGE_TYPE_2D, m_colorAttachmentFormat, imageExtent, 1, 1, VK_SAMPLE_COUNT_1_BIT, VK_IMAGE_TILING_OPTIMAL,
796                                                                                                                         VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
797
798                 m_colorAttachmentImage  = Image::createAndAlloc(vk, device, colorImageCreateInfo, m_context.getDefaultAllocator());
799
800                 const ImageViewCreateInfo       attachmentViewInfo              (m_colorAttachmentImage->object(), VK_IMAGE_VIEW_TYPE_2D, m_colorAttachmentFormat);
801                 m_attachmentView                        = createImageView(vk, device, &attachmentViewInfo);
802
803                 ImageCreateInfo                         depthImageCreateInfo    (vk::VK_IMAGE_TYPE_2D, VK_FORMAT_D16_UNORM, imageExtent, 1, 1, vk::VK_SAMPLE_COUNT_1_BIT, vk::VK_IMAGE_TILING_OPTIMAL,
804                                                                                                                          vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
805
806                 m_depthImage                            = Image::createAndAlloc(vk, device, depthImageCreateInfo, m_context.getDefaultAllocator());
807
808                 // Construct a depth  view from depth image
809                 const ImageViewCreateInfo       depthViewInfo                   (m_depthImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_D16_UNORM);
810                 m_depthiew                              = vk::createImageView(vk, device, &depthViewInfo);
811         }
812
813         {
814                 // Renderpass and Framebuffer
815                 RenderPassCreateInfo            renderPassCreateInfo;
816                 renderPassCreateInfo.addAttachment(AttachmentDescription(m_colorAttachmentFormat,                                               // format
817                                                                                                                                         VK_SAMPLE_COUNT_1_BIT,                                          // samples
818                                                                                                                                         VK_ATTACHMENT_LOAD_OP_CLEAR,                            // loadOp
819                                                                                                                                         VK_ATTACHMENT_STORE_OP_STORE ,                          // storeOp
820                                                                                                                                         VK_ATTACHMENT_LOAD_OP_DONT_CARE,                        // stencilLoadOp
821                                                                                                                                         VK_ATTACHMENT_STORE_OP_STORE ,                          // stencilLoadOp
822                                                                                                                                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // initialLauout
823                                                                                                                                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));     // finalLayout
824
825                 renderPassCreateInfo.addAttachment(AttachmentDescription(VK_FORMAT_D16_UNORM,                                                                           // format
826                                                                                                                                  vk::VK_SAMPLE_COUNT_1_BIT,                                                                     // samples
827                                                                                                                                  vk::VK_ATTACHMENT_LOAD_OP_CLEAR,                                                       // loadOp
828                                                                                                                                  vk::VK_ATTACHMENT_STORE_OP_DONT_CARE,                                          // storeOp
829                                                                                                                                  vk::VK_ATTACHMENT_LOAD_OP_DONT_CARE,                                           // stencilLoadOp
830                                                                                                                                  vk::VK_ATTACHMENT_STORE_OP_DONT_CARE,                                          // stencilLoadOp
831                                                                                                                                  vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,          // initialLauout
832                                                                                                                                  vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));        // finalLayout
833
834                 const VkAttachmentReference     colorAttachmentReference =
835                 {
836                         0u,                                                                                     // attachment
837                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL        // layout
838                 };
839
840                 const VkAttachmentReference depthAttachmentReference =
841                 {
842                         1u,                                                                                                                     // attachment
843                         vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL            // layout
844                 };
845
846                 const VkSubpassDescription      subpass =
847                 {
848                         (VkSubpassDescriptionFlags) 0,          //VkSubpassDescriptionFlags             flags;
849                         VK_PIPELINE_BIND_POINT_GRAPHICS,        //VkPipelineBindPoint                   pipelineBindPoint;
850                         0u,                                                                     //deUint32                                              inputAttachmentCount;
851                         DE_NULL,                                                        //const VkAttachmentReference*  pInputAttachments;
852                         1u,                                                                     //deUint32                                              colorAttachmentCount;
853                         &colorAttachmentReference,                      //const VkAttachmentReference*  pColorAttachments;
854                         DE_NULL,                                                        //const VkAttachmentReference*  pResolveAttachments;
855                         &depthAttachmentReference,                      //const VkAttachmentReference*  pDepthStencilAttachment;
856                         0u,                                                                     //deUint32                                              preserveAttachmentCount;
857                         DE_NULL,                                                        //const deUint32*                               pPreserveAttachments;
858                 };
859
860                 renderPassCreateInfo.addSubpass(subpass);
861                 m_renderPass = createRenderPass(vk, device, &renderPassCreateInfo);
862
863                 std::vector<vk::VkImageView> attachments(2);
864                 attachments[0] = *m_attachmentView;
865                 attachments[1] = *m_depthiew;
866
867                 FramebufferCreateInfo           framebufferCreateInfo(*m_renderPass, attachments, WIDTH, HEIGHT, 1);
868                 m_framebuffer = createFramebuffer(vk, device, &framebufferCreateInfo);
869         }
870 }
871
872 bool GraphicBasicTestInstance::checkImage (void)
873 {
874         const VkQueue                                           queue                   = m_context.getUniversalQueue();
875         const VkOffset3D                                        zeroOffset              = { 0, 0, 0 };
876         const tcu::ConstPixelBufferAccess       renderedFrame   = m_colorAttachmentImage->readSurface(queue, m_context.getDefaultAllocator(),
877                                                                                                                         VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, VK_IMAGE_ASPECT_COLOR_BIT);
878         int                                                                     colorNdx                = 0;
879         tcu::Texture2D                                          referenceFrame  (mapVkFormat(m_colorAttachmentFormat), WIDTH, HEIGHT);
880         referenceFrame.allocLevel(0);
881
882         for (int y = 0; y < HEIGHT/2; ++y)
883         for (int x = 0; x < WIDTH/2; ++x)
884                         referenceFrame.getLevel(0).setPixel(m_data[colorNdx].color, x, y);
885
886         colorNdx += 4;
887         for (int y =  HEIGHT/2; y < HEIGHT; ++y)
888         for (int x = 0; x < WIDTH/2; ++x)
889                         referenceFrame.getLevel(0).setPixel(m_data[colorNdx].color, x, y);
890
891         colorNdx += 4;
892         for (int y = 0; y < HEIGHT/2; ++y)
893         for (int x =  WIDTH/2; x < WIDTH; ++x)
894                         referenceFrame.getLevel(0).setPixel(m_data[colorNdx].color, x, y);
895
896         colorNdx += 4;
897         for (int y =  HEIGHT/2; y < HEIGHT; ++y)
898         for (int x =  WIDTH/2; x < WIDTH; ++x)
899                         referenceFrame.getLevel(0).setPixel(m_data[colorNdx].color, x, y);
900
901         return tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Result", "Image comparison result", referenceFrame.getLevel(0), renderedFrame, tcu::Vec4(0.01f), tcu::COMPARE_LOG_ON_ERROR);
902 }
903
904 class VertexShaderTestInstance : public GraphicBasicTestInstance
905 {
906 public:
907                                                         VertexShaderTestInstance        (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic);
908 protected:
909         virtual void                    createPipeline                          (void);
910         virtual tcu::TestStatus executeTest                                     (void);
911         virtual tcu::TestStatus checkResult                                     (VkQueryPool queryPool);
912         void                                    draw                                            (VkCommandBuffer cmdBuffer);
913 };
914
915 VertexShaderTestInstance::VertexShaderTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic)
916         : GraphicBasicTestInstance      (context, data, parametersGraphic)
917 {
918 }
919
920 void VertexShaderTestInstance::createPipeline (void)
921 {
922         const DeviceInterface&  vk              = m_context.getDeviceInterface();
923         const VkDevice                  device  = m_context.getDevice();
924
925         // Pipeline
926         Unique<VkShaderModule> vs(createShaderModule(vk, device, m_context.getBinaryCollection().get("vertex"), 0));
927         Unique<VkShaderModule> fs(createShaderModule(vk, device, m_context.getBinaryCollection().get("fragment"), 0));
928
929         const PipelineCreateInfo::ColorBlendState::Attachment attachmentState;
930
931         const PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
932         m_pipelineLayout = createPipelineLayout(vk, device, &pipelineLayoutCreateInfo);
933
934         const VkVertexInputBindingDescription vertexInputBindingDescription             =
935         {
936                 0,                                                                                      // binding;
937                 static_cast<deUint32>(sizeof(VertexData)),      // stride;
938                 VK_VERTEX_INPUT_RATE_VERTEX                             // inputRate
939         };
940
941         const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] =
942         {
943                 {
944                         0u,
945                         0u,
946                         VK_FORMAT_R32G32B32A32_SFLOAT,
947                         0u
948                 },      // VertexElementData::position
949                 {
950                         1u,
951                         0u,
952                         VK_FORMAT_R32G32B32A32_SFLOAT,
953                         static_cast<deUint32>(sizeof(tcu::Vec4))
954                 },      // VertexElementData::color
955         };
956
957         const VkPipelineVertexInputStateCreateInfo vf_info                      =
958         {                                                                                                                                       // sType;
959                 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,              // pNext;
960                 NULL,                                                                                                                   // flags;
961                 0u,                                                                                                                             // vertexBindingDescriptionCount;
962                 1u,                                                                                                                             // pVertexBindingDescriptions;
963                 &vertexInputBindingDescription,                                                                 // vertexAttributeDescriptionCount;
964                 2u,                                                                                                                             // pVertexAttributeDescriptions;
965                 vertexInputAttributeDescriptions
966         };
967
968         PipelineCreateInfo pipelineCreateInfo(*m_pipelineLayout, *m_renderPass, 0, (VkPipelineCreateFlags)0);
969         pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", VK_SHADER_STAGE_VERTEX_BIT));
970         pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", VK_SHADER_STAGE_FRAGMENT_BIT));
971         pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState());
972         pipelineCreateInfo.addState(PipelineCreateInfo::InputAssemblerState(m_parametersGraphic.primitiveTopology));
973         pipelineCreateInfo.addState(PipelineCreateInfo::ColorBlendState(1, &attachmentState));
974
975         const VkViewport        viewport        =
976         {
977                 0.0f,           // float x;
978                 0.0f,           // float y;
979                 WIDTH,  // float width;
980                 HEIGHT, // float height;
981                 0.0f,   // float minDepth;
982                 1.0f    // float maxDepth;
983         };
984
985         const VkRect2D          scissor         =
986         {
987                 {
988                         0,              // deInt32 x
989                         0,              // deInt32 y
990                 },              // VkOffset2D   offset;
991                 {
992                         WIDTH,  // deInt32 width;
993                         HEIGHT, // deInt32 height
994                 },              // VkExtent2D   extent;
995         };
996         pipelineCreateInfo.addState(PipelineCreateInfo::ViewportState(1u, std::vector<VkViewport>(1, viewport), std::vector<VkRect2D>(1, scissor)));
997         pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState());
998         pipelineCreateInfo.addState(PipelineCreateInfo::RasterizerState());
999         pipelineCreateInfo.addState(PipelineCreateInfo::MultiSampleState());
1000         pipelineCreateInfo.addState(vf_info);
1001         m_pipeline = createGraphicsPipeline(vk, device, DE_NULL, &pipelineCreateInfo);
1002 }
1003
1004 tcu::TestStatus VertexShaderTestInstance::executeTest (void)
1005 {
1006         const DeviceInterface&                                  vk                                              = m_context.getDeviceInterface();
1007         const VkDevice                                                  device                                  = m_context.getDevice();
1008         const VkQueue                                                   queue                                   = m_context.getUniversalQueue();
1009         const deUint32                                                  queueFamilyIndex                = m_context.getUniversalQueueFamilyIndex();
1010
1011         const CmdPoolCreateInfo                                 cmdPoolCreateInfo               (queueFamilyIndex);
1012         const Move<VkCommandPool>                               cmdPool                                 = createCommandPool(vk, device, &cmdPoolCreateInfo);
1013         const Unique<VkQueryPool>                               queryPool                               (makeQueryPool(vk, device, m_parametersGraphic.queryStatisticFlags));
1014
1015         const VkDeviceSize                                              vertexBufferOffset              = 0u;
1016         const de::SharedPtr<Buffer>                             vertexBufferSp                  = creatAndFillVertexBuffer();
1017         const VkBuffer                                                  vertexBuffer                    = vertexBufferSp->object();
1018
1019         const Unique<VkCommandBuffer>                   cmdBuffer                               (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1020
1021         beginCommandBuffer(vk, *cmdBuffer);
1022         {
1023                 const VkRect2D                          renderArea                              = { { 0, 0 }, { WIDTH, HEIGHT } };
1024                 std::vector<VkClearValue>       renderPassClearValues   (2);
1025                 deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1026                 const RenderPassBeginInfo       renderPassBegin                 (*m_renderPass, *m_framebuffer, renderArea, renderPassClearValues);
1027
1028                 transition2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1029                 transition2DImage(vk, *cmdBuffer, m_depthImage->object(), VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
1030
1031                 vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, 1u);
1032
1033                 vk.cmdBeginRenderPass(*cmdBuffer, &renderPassBegin, VK_SUBPASS_CONTENTS_INLINE);
1034
1035                 vk.cmdBeginQuery(*cmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
1036                 vk.cmdBindVertexBuffers(*cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
1037                 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1038                 draw(*cmdBuffer);
1039                 vk.cmdEndQuery(*cmdBuffer, *queryPool, 0u);
1040
1041                 vk.cmdEndRenderPass(*cmdBuffer);
1042
1043                 transition2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 0u, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1044         }
1045         vk.endCommandBuffer(*cmdBuffer);
1046
1047         // Wait for completion
1048         submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1049         return checkResult (*queryPool);
1050 }
1051
1052 tcu::TestStatus VertexShaderTestInstance::checkResult (VkQueryPool queryPool)
1053 {
1054         const DeviceInterface&  vk                      = m_context.getDeviceInterface();
1055         const VkDevice                  device          = m_context.getDevice();
1056         deUint64                                result          = 0u;
1057         deUint64                                expectedMin     = 0u;
1058         deUint64                                expectedMax     = 0u;
1059         switch(m_parametersGraphic.queryStatisticFlags)
1060         {
1061                 case VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT:
1062                         expectedMax = expectedMin = 16u;
1063                         break;
1064                 case VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT:
1065                         expectedMin =   m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST                                    ? 15u :
1066                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY                 ?  8u :
1067                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY                ? 14u :
1068                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY             ?  6u :
1069                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY    ?  8u :
1070                                                         16u;
1071                         expectedMax =   m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY             ? 12u : 16u;
1072                         break;
1073                 case VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT:
1074                         expectedMax = expectedMin =     m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST                                               ? 16u :
1075                                                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST                                                ?  8u :
1076                                                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP                                               ? 15u :
1077                                                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST                                    ?  5u :
1078                                                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP                                   ?  8u :
1079                                                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN                                             ? 14u :
1080                                                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY                 ?  4u :
1081                                                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY                ? 13u :
1082                                                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY             ?  2u :
1083                                                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY    ?  6u :
1084                                                                                 0u;
1085                         break;
1086                 case VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT:
1087                         expectedMin =   m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST                                               ?     9u :
1088                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST                                                ?   192u :
1089                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP                                               ?   448u :
1090                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST                                    ?  2016u :
1091                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP                                   ?  4096u :
1092                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN                                             ? 10208u :
1093                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY                 ?   128u :
1094                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY                ?   416u :
1095                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY             ?   992u :
1096                                                         m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY    ?  3072u :
1097                                                         0u;
1098                         expectedMax = 4u * expectedMin;
1099                         break;
1100                 default:
1101                         DE_ASSERT(0);
1102                         break;
1103         }
1104
1105         VK_CHECK(vk.getQueryPoolResults(device, queryPool, 0u, 1u, sizeof(deUint64), &result, 0u, VK_QUERY_RESULT_64_BIT));
1106         if (result < expectedMin || result > expectedMax)
1107                 return tcu::TestStatus::fail("QueryPoolResults incorrect");
1108
1109         if (m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP && !checkImage())
1110                 return tcu::TestStatus::fail("Result image doesn't match expected image.");
1111
1112         return tcu::TestStatus::pass("Pass");
1113 }
1114
1115 void VertexShaderTestInstance::draw (VkCommandBuffer cmdBuffer)
1116 {
1117         const DeviceInterface& vk = m_context.getDeviceInterface();
1118         switch(m_parametersGraphic.primitiveTopology)
1119         {
1120                 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
1121                 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
1122                 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
1123                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
1124                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
1125                 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
1126                 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
1127                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
1128                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
1129                         vk.cmdDraw(cmdBuffer, 16u, 1u, 0u, 0u);
1130                         break;
1131                 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
1132                         vk.cmdDraw(cmdBuffer, 4u, 1u, 0u,  0u);
1133                         vk.cmdDraw(cmdBuffer, 4u, 1u, 4u,  1u);
1134                         vk.cmdDraw(cmdBuffer, 4u, 1u, 8u,  2u);
1135                         vk.cmdDraw(cmdBuffer, 4u, 1u, 12u, 3u);
1136                         break;
1137                 default:
1138                         DE_ASSERT(0);
1139                         break;
1140         }
1141 }
1142
1143 class VertexShaderSecondaryTestInstance : public VertexShaderTestInstance
1144 {
1145 public:
1146                                                         VertexShaderSecondaryTestInstance       (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic);
1147 protected:
1148         virtual tcu::TestStatus executeTest                                                     (void);
1149 };
1150
1151 VertexShaderSecondaryTestInstance::VertexShaderSecondaryTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic)
1152         : VertexShaderTestInstance      (context, data, parametersGraphic)
1153 {
1154 }
1155
1156 tcu::TestStatus VertexShaderSecondaryTestInstance::executeTest (void)
1157 {
1158         const DeviceInterface&                                  vk                                              = m_context.getDeviceInterface();
1159         const VkDevice                                                  device                                  = m_context.getDevice();
1160         const VkQueue                                                   queue                                   = m_context.getUniversalQueue();
1161         const deUint32                                                  queueFamilyIndex                = m_context.getUniversalQueueFamilyIndex();
1162
1163         const CmdPoolCreateInfo                                 cmdPoolCreateInfo               (queueFamilyIndex);
1164         const Move<VkCommandPool>                               cmdPool                                 = createCommandPool(vk, device, &cmdPoolCreateInfo);
1165         const Unique<VkQueryPool>                               queryPool                               (makeQueryPool(vk, device, m_parametersGraphic.queryStatisticFlags));
1166
1167         const VkDeviceSize                                              vertexBufferOffset              = 0u;
1168         const de::SharedPtr<Buffer>                             vertexBufferSp                  = creatAndFillVertexBuffer();
1169         const VkBuffer                                                  vertexBuffer                    = vertexBufferSp->object();
1170
1171         const Unique<VkCommandBuffer>                   primaryCmdBuffer                (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1172         const Unique<VkCommandBuffer>                   secondaryCmdBuffer              (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY));
1173
1174         beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
1175                 vk.cmdBindPipeline(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1176                 vk.cmdBeginQuery(*secondaryCmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
1177                 vk.cmdBindVertexBuffers(*secondaryCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1178                 draw(*secondaryCmdBuffer);
1179                 vk.cmdEndQuery(*secondaryCmdBuffer, *queryPool, 0u);
1180         vk.endCommandBuffer(*secondaryCmdBuffer);
1181
1182         beginCommandBuffer(vk, *primaryCmdBuffer);
1183         {
1184                 const VkRect2D                          renderArea                              = { { 0, 0 }, { WIDTH, HEIGHT } };
1185                 std::vector<VkClearValue>       renderPassClearValues   (2);
1186                 deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1187                 const RenderPassBeginInfo       renderPassBegin                 (*m_renderPass, *m_framebuffer, renderArea, renderPassClearValues);
1188
1189                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1190                 transition2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
1191
1192                 vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, 1u);
1193
1194                 vk.cmdBeginRenderPass(*primaryCmdBuffer, &renderPassBegin, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
1195                 vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &secondaryCmdBuffer.get());
1196                 vk.cmdEndRenderPass(*primaryCmdBuffer);
1197                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1198         }
1199         vk.endCommandBuffer(*primaryCmdBuffer);
1200
1201         // Wait for completion
1202         submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
1203         return checkResult (*queryPool);
1204 }
1205
1206 class VertexShaderSecondaryInheritedTestInstance : public VertexShaderTestInstance
1207 {
1208 public:
1209                                                         VertexShaderSecondaryInheritedTestInstance      (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic);
1210 protected:
1211         void                                    checkExtensions                                         (void);
1212         virtual tcu::TestStatus executeTest                                                     (void);
1213 };
1214
1215 VertexShaderSecondaryInheritedTestInstance::VertexShaderSecondaryInheritedTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic)
1216         : VertexShaderTestInstance      (context, data, parametersGraphic)
1217 {
1218 }
1219
1220 void VertexShaderSecondaryInheritedTestInstance::checkExtensions (void)
1221 {
1222         StatisticQueryTestInstance::checkExtensions();
1223         if (!m_context.getDeviceFeatures().inheritedQueries)
1224                 throw tcu::NotSupportedError("Inherited queries are not supported");
1225 }
1226
1227 tcu::TestStatus VertexShaderSecondaryInheritedTestInstance::executeTest (void)
1228 {
1229         const DeviceInterface&                                  vk                                              = m_context.getDeviceInterface();
1230         const VkDevice                                                  device                                  = m_context.getDevice();
1231         const VkQueue                                                   queue                                   = m_context.getUniversalQueue();
1232         const deUint32                                                  queueFamilyIndex                = m_context.getUniversalQueueFamilyIndex();
1233
1234         const CmdPoolCreateInfo                                 cmdPoolCreateInfo               (queueFamilyIndex);
1235         const Move<VkCommandPool>                               cmdPool                                 = createCommandPool(vk, device, &cmdPoolCreateInfo);
1236         const Unique<VkQueryPool>                               queryPool                               (makeQueryPool(vk, device, m_parametersGraphic.queryStatisticFlags));
1237
1238         const VkDeviceSize                                              vertexBufferOffset              = 0u;
1239         const de::SharedPtr<Buffer>                             vertexBufferSp                  = creatAndFillVertexBuffer();
1240         const VkBuffer                                                  vertexBuffer                    = vertexBufferSp->object();
1241
1242         const Unique<VkCommandBuffer>                   primaryCmdBuffer                (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1243         const Unique<VkCommandBuffer>                   secondaryCmdBuffer              (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY));
1244
1245         beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
1246                 vk.cmdBindPipeline(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1247                 vk.cmdBindVertexBuffers(*secondaryCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1248                 draw(*secondaryCmdBuffer);
1249         vk.endCommandBuffer(*secondaryCmdBuffer);
1250
1251         beginCommandBuffer(vk, *primaryCmdBuffer);
1252         {
1253                 const VkRect2D                          renderArea                              = { { 0, 0 }, { WIDTH, HEIGHT } };
1254                 std::vector<VkClearValue>       renderPassClearValues   (2);
1255                 deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1256                 const RenderPassBeginInfo       renderPassBegin                 (*m_renderPass, *m_framebuffer, renderArea, renderPassClearValues);
1257
1258                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1259                 transition2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
1260
1261                 vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, 1u);
1262                 vk.cmdBeginQuery(*primaryCmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
1263
1264                 vk.cmdBeginRenderPass(*primaryCmdBuffer, &renderPassBegin, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
1265                 vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &secondaryCmdBuffer.get());
1266                 vk.cmdEndRenderPass(*primaryCmdBuffer);
1267                 vk.cmdEndQuery(*primaryCmdBuffer, *queryPool, 0u);
1268                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1269         }
1270         vk.endCommandBuffer(*primaryCmdBuffer);
1271
1272         // Wait for completion
1273         submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
1274         return checkResult (*queryPool);
1275 }
1276
1277 class GeometryShaderTestInstance : public GraphicBasicTestInstance
1278 {
1279 public:
1280                                                         GeometryShaderTestInstance      (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic);
1281 protected:
1282         virtual void                    checkExtensions                         (void);
1283         virtual void                    createPipeline                          (void);
1284         virtual tcu::TestStatus executeTest                                     (void);
1285         tcu::TestStatus                 checkResult                                     (VkQueryPool queryPool);
1286         void                                    draw                                            (VkCommandBuffer cmdBuffer);
1287 };
1288
1289 GeometryShaderTestInstance::GeometryShaderTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic)
1290         : GraphicBasicTestInstance      (context, data, parametersGraphic)
1291 {
1292 }
1293
1294 void GeometryShaderTestInstance::checkExtensions (void)
1295 {
1296         StatisticQueryTestInstance::checkExtensions();
1297         if (!m_context.getDeviceFeatures().geometryShader)
1298                 throw tcu::NotSupportedError("Geometry shader are not supported");
1299 }
1300
1301 void GeometryShaderTestInstance::createPipeline (void)
1302 {
1303         const DeviceInterface&  vk              = m_context.getDeviceInterface();
1304         const VkDevice                  device  = m_context.getDevice();
1305
1306         // Pipeline
1307         Unique<VkShaderModule> vs(createShaderModule(vk, device, m_context.getBinaryCollection().get("vertex"), (VkShaderModuleCreateFlags)0));
1308         Unique<VkShaderModule> gs(createShaderModule(vk, device, m_context.getBinaryCollection().get("geometry"), (VkShaderModuleCreateFlags)0));
1309         Unique<VkShaderModule> fs(createShaderModule(vk, device, m_context.getBinaryCollection().get("fragment"), (VkShaderModuleCreateFlags)0));
1310
1311         const PipelineCreateInfo::ColorBlendState::Attachment attachmentState;
1312
1313         const PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
1314         m_pipelineLayout = createPipelineLayout(vk, device, &pipelineLayoutCreateInfo);
1315
1316         const VkVertexInputBindingDescription vertexInputBindingDescription             =
1317         {
1318                 0u,                                                                                     // binding;
1319                 static_cast<deUint32>(sizeof(VertexData)),      // stride;
1320                 VK_VERTEX_INPUT_RATE_VERTEX                                     // inputRate
1321         };
1322
1323         const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] =
1324         {
1325                 {
1326                         0u,
1327                         0u,
1328                         VK_FORMAT_R32G32B32A32_SFLOAT,
1329                         0u
1330                 },      // VertexElementData::position
1331                 {
1332                         1u,
1333                         0u,
1334                         VK_FORMAT_R32G32B32A32_SFLOAT,
1335                         static_cast<deUint32>(sizeof(tcu::Vec4))
1336                 },      // VertexElementData::color
1337         };
1338
1339         const VkPipelineVertexInputStateCreateInfo vf_info                      =
1340         {                                                                                                                                       // sType;
1341                 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,              // pNext;
1342                 NULL,                                                                                                                   // flags;
1343                 0u,                                                                                                                             // vertexBindingDescriptionCount;
1344                 1,                                                                                                                              // pVertexBindingDescriptions;
1345                 &vertexInputBindingDescription,                                                                 // vertexAttributeDescriptionCount;
1346                 2,                                                                                                                              // pVertexAttributeDescriptions;
1347                 vertexInputAttributeDescriptions
1348         };
1349
1350         PipelineCreateInfo pipelineCreateInfo(*m_pipelineLayout, *m_renderPass, 0, (VkPipelineCreateFlags)0);
1351         pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", VK_SHADER_STAGE_VERTEX_BIT));
1352         pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*gs, "main", VK_SHADER_STAGE_GEOMETRY_BIT));
1353         pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", VK_SHADER_STAGE_FRAGMENT_BIT));
1354         pipelineCreateInfo.addState(PipelineCreateInfo::InputAssemblerState(m_parametersGraphic.primitiveTopology));
1355         pipelineCreateInfo.addState(PipelineCreateInfo::ColorBlendState(1, &attachmentState));
1356
1357         const VkViewport        viewport        =
1358         {
1359                 0.0f,           // float x;
1360                 0.0f,           // float y;
1361                 WIDTH,  // float width;
1362                 HEIGHT, // float height;
1363                 0.0f,   // float minDepth;
1364                 1.0f    // float maxDepth;
1365         };
1366
1367         const VkRect2D          scissor         =
1368         {
1369                 {
1370                         0,              // deInt32 x
1371                         0,              // deInt32 y
1372                 },              // VkOffset2D   offset;
1373                 {
1374                         WIDTH,  // deInt32 width;
1375                         HEIGHT, // deInt32 height
1376                 },              // VkExtent2D   extent;
1377         };
1378         pipelineCreateInfo.addState(PipelineCreateInfo::ViewportState(1, std::vector<VkViewport>(1, viewport), std::vector<VkRect2D>(1, scissor)));
1379
1380         if (m_context.getDeviceFeatures().depthBounds)
1381                 pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState(true, true, VK_COMPARE_OP_GREATER_OR_EQUAL, true));
1382         else
1383                 pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState());
1384
1385         pipelineCreateInfo.addState(PipelineCreateInfo::RasterizerState(false));
1386         pipelineCreateInfo.addState(PipelineCreateInfo::MultiSampleState());
1387         pipelineCreateInfo.addState(vf_info);
1388         m_pipeline = createGraphicsPipeline(vk, device, DE_NULL, &pipelineCreateInfo);
1389 }
1390
1391 tcu::TestStatus GeometryShaderTestInstance::executeTest (void)
1392 {
1393         const DeviceInterface&                                  vk                                              = m_context.getDeviceInterface();
1394         const VkDevice                                                  device                                  = m_context.getDevice();
1395         const VkQueue                                                   queue                                   = m_context.getUniversalQueue();
1396         const deUint32                                                  queueFamilyIndex                = m_context.getUniversalQueueFamilyIndex();
1397
1398         const CmdPoolCreateInfo                                 cmdPoolCreateInfo               (queueFamilyIndex);
1399         const Move<VkCommandPool>                               cmdPool                                 = createCommandPool(vk, device, &cmdPoolCreateInfo);
1400         const Unique<VkQueryPool>                               queryPool                               (makeQueryPool(vk, device, m_parametersGraphic.queryStatisticFlags));
1401
1402         const VkDeviceSize                                              vertexBufferOffset              = 0u;
1403         const de::SharedPtr<Buffer>                             vertexBufferSp                  = creatAndFillVertexBuffer();
1404         const VkBuffer                                                  vertexBuffer                    = vertexBufferSp->object();
1405
1406         const Unique<VkCommandBuffer>                   cmdBuffer                               (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1407
1408         beginCommandBuffer(vk, *cmdBuffer);
1409         {
1410                 const VkRect2D                          renderArea                              = { { 0, 0 }, { WIDTH, HEIGHT } };
1411                 std::vector<VkClearValue>       renderPassClearValues   (2);
1412                 deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1413                 const RenderPassBeginInfo       renderPassBegin                 (*m_renderPass, *m_framebuffer, renderArea, renderPassClearValues);
1414
1415                 transition2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1416                 transition2DImage(vk, *cmdBuffer, m_depthImage->object(), VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
1417
1418                 vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, 1u);
1419
1420                 vk.cmdBeginRenderPass(*cmdBuffer, &renderPassBegin, VK_SUBPASS_CONTENTS_INLINE);
1421
1422                 vk.cmdBeginQuery(*cmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
1423                 vk.cmdBindVertexBuffers(*cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
1424                 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1425
1426                 draw(*cmdBuffer);
1427
1428                 vk.cmdEndQuery(*cmdBuffer, *queryPool, 0u);
1429
1430                 vk.cmdEndRenderPass(*cmdBuffer);
1431
1432                 transition2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1433         }
1434         vk.endCommandBuffer(*cmdBuffer);
1435
1436         // Wait for completion
1437         submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1438         return checkResult(*queryPool);
1439 }
1440
1441 tcu::TestStatus GeometryShaderTestInstance::checkResult (VkQueryPool queryPool)
1442 {
1443         const DeviceInterface&  vk                      = m_context.getDeviceInterface();
1444         const VkDevice                  device          = m_context.getDevice();
1445         deUint64                                result          = 0u;
1446         deUint64                                expected        = 0u;
1447
1448         switch(m_parametersGraphic.queryStatisticFlags)
1449         {
1450                 case VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT:
1451                         expected =      m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST                                               ? 16u :
1452                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST                                                ? 8u :
1453                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP                                               ? 15u :
1454                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST                                    ? 4u :
1455                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP                                   ? 4u :
1456                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN                                             ? 14u :
1457                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY                 ? 4u :
1458                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY                ? 13u :
1459                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY             ? 2u :
1460                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY    ? 6u :
1461                                                 0u;
1462                         break;
1463                 case VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT:
1464                 case VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT:
1465                 case VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT:
1466                         expected =      m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST                                               ? 112u :
1467                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST                                                ? 32u :
1468                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP                                               ? 60u :
1469                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST                                    ? 8u :
1470                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP                                   ? 8u :
1471                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN                                             ? 28u :
1472                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY                 ? 16u :
1473                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY                ? 52u :
1474                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY             ? 4u :
1475                                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY    ? 12u :
1476                                                 0u;
1477                         break;
1478                 default:
1479                         DE_ASSERT(0);
1480                 break;
1481         }
1482         VK_CHECK(vk.getQueryPoolResults(device, queryPool, 0u, 1u, sizeof(deUint64), &result, 0u, VK_QUERY_RESULT_64_BIT));
1483         if (expected != result)
1484                 return tcu::TestStatus::fail("QueryPoolResults incorrect");
1485
1486         if ( (m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST || m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP ) && !checkImage())
1487                 return tcu::TestStatus::fail("Result image doesn't match expected image.");
1488
1489         return tcu::TestStatus::pass("Pass");
1490 }
1491
1492 void GeometryShaderTestInstance::draw (VkCommandBuffer cmdBuffer)
1493 {
1494         const DeviceInterface&  vk                      = m_context.getDeviceInterface();
1495         if (m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP ||
1496                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
1497         {
1498                 vk.cmdDraw(cmdBuffer, 3u, 1u,  0u,  1u);
1499                 vk.cmdDraw(cmdBuffer, 3u, 1u,  4u,  1u);
1500                 vk.cmdDraw(cmdBuffer, 3u, 1u,  8u,  2u);
1501                 vk.cmdDraw(cmdBuffer, 3u, 1u, 12u,  3u);
1502         }
1503         else
1504         {
1505                 vk.cmdDraw(cmdBuffer, 16u, 1u, 0u,  0u);
1506         }
1507 }
1508
1509 class GeometryShaderSecondaryTestInstance : public GeometryShaderTestInstance
1510 {
1511 public:
1512                                                         GeometryShaderSecondaryTestInstance     (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic);
1513 protected:
1514         virtual tcu::TestStatus executeTest                                                     (void);
1515 };
1516
1517 GeometryShaderSecondaryTestInstance::GeometryShaderSecondaryTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic)
1518         : GeometryShaderTestInstance    (context, data, parametersGraphic)
1519 {
1520 }
1521
1522 tcu::TestStatus GeometryShaderSecondaryTestInstance::executeTest (void)
1523 {
1524         const DeviceInterface&                                  vk                                              = m_context.getDeviceInterface();
1525         const VkDevice                                                  device                                  = m_context.getDevice();
1526         const VkQueue                                                   queue                                   = m_context.getUniversalQueue();
1527         const deUint32                                                  queueFamilyIndex                = m_context.getUniversalQueueFamilyIndex();
1528
1529         const CmdPoolCreateInfo                                 cmdPoolCreateInfo               (queueFamilyIndex);
1530         const Move<VkCommandPool>                               cmdPool                                 = createCommandPool(vk, device, &cmdPoolCreateInfo);
1531         const Unique<VkQueryPool>                               queryPool                               (makeQueryPool(vk, device, m_parametersGraphic.queryStatisticFlags));
1532
1533         const VkDeviceSize                                              vertexBufferOffset              = 0;
1534         const de::SharedPtr<Buffer>                             vertexBufferSp                  = creatAndFillVertexBuffer();
1535         const VkBuffer                                                  vertexBuffer                    = vertexBufferSp->object();
1536
1537         const Unique<VkCommandBuffer>                   primaryCmdBuffer                (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1538         const Unique<VkCommandBuffer>                   secondaryCmdBuffer              (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY));
1539
1540         beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
1541                 vk.cmdBindPipeline(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1542                 vk.cmdBeginQuery(*secondaryCmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
1543                 vk.cmdBindVertexBuffers(*secondaryCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1544                 draw(*secondaryCmdBuffer);
1545                 vk.cmdEndQuery(*secondaryCmdBuffer, *queryPool, 0u);
1546         vk.endCommandBuffer(*secondaryCmdBuffer);
1547
1548         beginCommandBuffer(vk, *primaryCmdBuffer);
1549         {
1550                 const VkRect2D                          renderArea                              = { { 0, 0 }, { WIDTH, HEIGHT } };
1551                 std::vector<VkClearValue>       renderPassClearValues   (2);
1552                 deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1553                 const RenderPassBeginInfo       renderPassBegin                 (*m_renderPass, *m_framebuffer, renderArea, renderPassClearValues);
1554
1555                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1556                 transition2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
1557
1558                 vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, 1u);
1559                 vk.cmdBeginRenderPass(*primaryCmdBuffer, &renderPassBegin, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
1560                 vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &secondaryCmdBuffer.get());
1561                 vk.cmdEndRenderPass(*primaryCmdBuffer);
1562
1563                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1564         }
1565         vk.endCommandBuffer(*primaryCmdBuffer);
1566
1567         // Wait for completion
1568         submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
1569         return checkResult(*queryPool);
1570 }
1571
1572 class GeometryShaderSecondaryInheritedTestInstance : public GeometryShaderTestInstance
1573 {
1574 public:
1575                                                         GeometryShaderSecondaryInheritedTestInstance    (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic);
1576 protected:
1577         void                                    checkExtensions                                         (void);
1578         virtual tcu::TestStatus executeTest                                                     (void);
1579 };
1580
1581 GeometryShaderSecondaryInheritedTestInstance::GeometryShaderSecondaryInheritedTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic)
1582         : GeometryShaderTestInstance    (context, data, parametersGraphic)
1583 {
1584 }
1585
1586 void GeometryShaderSecondaryInheritedTestInstance::checkExtensions (void)
1587 {
1588         GeometryShaderTestInstance::checkExtensions();
1589         if (!m_context.getDeviceFeatures().inheritedQueries)
1590                 throw tcu::NotSupportedError("Inherited queries are not supported");
1591 }
1592
1593 tcu::TestStatus GeometryShaderSecondaryInheritedTestInstance::executeTest (void)
1594 {
1595         const DeviceInterface&                                  vk                                              = m_context.getDeviceInterface();
1596         const VkDevice                                                  device                                  = m_context.getDevice();
1597         const VkQueue                                                   queue                                   = m_context.getUniversalQueue();
1598         const deUint32                                                  queueFamilyIndex                = m_context.getUniversalQueueFamilyIndex();
1599
1600         const CmdPoolCreateInfo                                 cmdPoolCreateInfo               (queueFamilyIndex);
1601         const Move<VkCommandPool>                               cmdPool                                 = createCommandPool(vk, device, &cmdPoolCreateInfo);
1602         const Unique<VkQueryPool>                               queryPool                               (makeQueryPool(vk, device, m_parametersGraphic.queryStatisticFlags));
1603
1604         const VkDeviceSize                                              vertexBufferOffset              = 0u;
1605         const de::SharedPtr<Buffer>                             vertexBufferSp                  = creatAndFillVertexBuffer();
1606         const VkBuffer                                                  vertexBuffer                    = vertexBufferSp->object();
1607
1608         const Unique<VkCommandBuffer>                   primaryCmdBuffer                (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1609         const Unique<VkCommandBuffer>                   secondaryCmdBuffer              (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY));
1610
1611         beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
1612                 vk.cmdBindPipeline(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1613                 vk.cmdBindVertexBuffers(*secondaryCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1614                 draw(*secondaryCmdBuffer);
1615         vk.endCommandBuffer(*secondaryCmdBuffer);
1616
1617         beginCommandBuffer(vk, *primaryCmdBuffer);
1618         {
1619                 const VkRect2D                          renderArea                              = { { 0, 0 }, { WIDTH, HEIGHT } };
1620                 std::vector<VkClearValue>       renderPassClearValues   (2);
1621                 deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1622                 const RenderPassBeginInfo       renderPassBegin                 (*m_renderPass, *m_framebuffer, renderArea, renderPassClearValues);
1623
1624                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1625                 transition2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
1626
1627                 vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, 1u);
1628                 vk.cmdBeginQuery(*primaryCmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
1629                 vk.cmdBeginRenderPass(*primaryCmdBuffer, &renderPassBegin, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
1630                 vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &secondaryCmdBuffer.get());
1631                 vk.cmdEndRenderPass(*primaryCmdBuffer);
1632                 vk.cmdEndQuery(*primaryCmdBuffer, *queryPool, 0u);
1633
1634                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1635         }
1636         vk.endCommandBuffer(*primaryCmdBuffer);
1637
1638         // Wait for completion
1639         submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
1640         return checkResult(*queryPool);
1641 }
1642
1643 class TessellationShaderTestInstance : public GraphicBasicTestInstance
1644 {
1645 public:
1646                                                         TessellationShaderTestInstance  (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic);
1647 protected:
1648         virtual void                    checkExtensions                         (void);
1649         virtual void                    createPipeline                          (void);
1650         virtual tcu::TestStatus executeTest                                     (void);
1651         virtual tcu::TestStatus checkResult                                     (VkQueryPool queryPool);
1652         void                                    draw                                            (VkCommandBuffer cmdBuffer);
1653 };
1654
1655 TessellationShaderTestInstance::TessellationShaderTestInstance  (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic)
1656         : GraphicBasicTestInstance      (context, data, parametersGraphic)
1657 {
1658 }
1659
1660 void TessellationShaderTestInstance::checkExtensions (void)
1661 {
1662         StatisticQueryTestInstance::checkExtensions();
1663         if (!m_context.getDeviceFeatures().tessellationShader)
1664                 throw tcu::NotSupportedError("Tessellation shader are not supported");
1665 }
1666
1667
1668 void TessellationShaderTestInstance::createPipeline (void)
1669 {
1670         const DeviceInterface&  vk              = m_context.getDeviceInterface();
1671         const VkDevice                  device  = m_context.getDevice();
1672
1673         // Pipeline
1674         Unique<VkShaderModule> vs(createShaderModule(vk, device, m_context.getBinaryCollection().get("vertex"), (VkShaderModuleCreateFlags)0));
1675         Unique<VkShaderModule> tc(createShaderModule(vk, device, m_context.getBinaryCollection().get("tessellation_control"), (VkShaderModuleCreateFlags)0));
1676         Unique<VkShaderModule> te(createShaderModule(vk, device, m_context.getBinaryCollection().get("tessellation_evaluation"), (VkShaderModuleCreateFlags)0));
1677         Unique<VkShaderModule> fs(createShaderModule(vk, device, m_context.getBinaryCollection().get("fragment"), (VkShaderModuleCreateFlags)0));
1678
1679         const PipelineCreateInfo::ColorBlendState::Attachment attachmentState;
1680
1681         const PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
1682         m_pipelineLayout = createPipelineLayout(vk, device, &pipelineLayoutCreateInfo);
1683
1684         const VkVertexInputBindingDescription vertexInputBindingDescription             =
1685         {
1686                 0u,                                                                                     // binding;
1687                 static_cast<deUint32>(sizeof(VertexData)),      // stride;
1688                 VK_VERTEX_INPUT_RATE_VERTEX                                     // inputRate
1689         };
1690
1691         const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] =
1692         {
1693                 {
1694                         0u,
1695                         0u,
1696                         VK_FORMAT_R32G32B32A32_SFLOAT,
1697                         0u
1698                 },      // VertexElementData::position
1699                 {
1700                         1u,
1701                         0u,
1702                         VK_FORMAT_R32G32B32A32_SFLOAT,
1703                         static_cast<deUint32>(sizeof(tcu::Vec4))
1704                 },      // VertexElementData::color
1705         };
1706
1707         const VkPipelineVertexInputStateCreateInfo vf_info                      =
1708         {                                                                                                                                       // sType;
1709                 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,              // pNext;
1710                 NULL,                                                                                                                   // flags;
1711                 0u,                                                                                                                             // vertexBindingDescriptionCount;
1712                 1u,                                                                                                                             // pVertexBindingDescriptions;
1713                 &vertexInputBindingDescription,                                                                 // vertexAttributeDescriptionCount;
1714                 2u,                                                                                                                             // pVertexAttributeDescriptions;
1715                 vertexInputAttributeDescriptions
1716         };
1717
1718         PipelineCreateInfo pipelineCreateInfo(*m_pipelineLayout, *m_renderPass, 0, (VkPipelineCreateFlags)0);
1719         pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", VK_SHADER_STAGE_VERTEX_BIT));
1720         pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*tc, "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT));
1721         pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*te, "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT));
1722         pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", VK_SHADER_STAGE_FRAGMENT_BIT));
1723         pipelineCreateInfo.addState     (PipelineCreateInfo::TessellationState(4));
1724         pipelineCreateInfo.addState(PipelineCreateInfo::InputAssemblerState(VK_PRIMITIVE_TOPOLOGY_PATCH_LIST));
1725         pipelineCreateInfo.addState(PipelineCreateInfo::ColorBlendState(1, &attachmentState));
1726
1727         const VkViewport        viewport        =
1728         {
1729                 0.0f,           // float x;
1730                 0.0f,           // float y;
1731                 WIDTH,  // float width;
1732                 HEIGHT, // float height;
1733                 0.0f,   // float minDepth;
1734                 1.0f    // float maxDepth;
1735         };
1736
1737         const VkRect2D          scissor         =
1738         {
1739                 {
1740                         0,              // deInt32 x
1741                         0,              // deInt32 y
1742                 },              // VkOffset2D   offset;
1743                 {
1744                         WIDTH,  // deInt32 width;
1745                         HEIGHT, // deInt32 height
1746                 },              // VkExtent2D   extent;
1747         };
1748         pipelineCreateInfo.addState(PipelineCreateInfo::ViewportState(1, std::vector<VkViewport>(1, viewport), std::vector<VkRect2D>(1, scissor)));
1749         pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState());
1750         pipelineCreateInfo.addState(PipelineCreateInfo::RasterizerState());
1751         pipelineCreateInfo.addState(PipelineCreateInfo::MultiSampleState());
1752         pipelineCreateInfo.addState(vf_info);
1753         m_pipeline = createGraphicsPipeline(vk, device, DE_NULL, &pipelineCreateInfo);
1754 }
1755
1756 tcu::TestStatus TessellationShaderTestInstance::executeTest (void)
1757 {
1758         const DeviceInterface&                                  vk                                              = m_context.getDeviceInterface();
1759         const VkDevice                                                  device                                  = m_context.getDevice();
1760         const VkQueue                                                   queue                                   = m_context.getUniversalQueue();
1761         const deUint32                                                  queueFamilyIndex                = m_context.getUniversalQueueFamilyIndex();
1762
1763         const CmdPoolCreateInfo                                 cmdPoolCreateInfo               (queueFamilyIndex);
1764         const Move<VkCommandPool>                               cmdPool                                 = createCommandPool(vk, device, &cmdPoolCreateInfo);
1765         const Unique<VkQueryPool>                               queryPool                               (makeQueryPool(vk, device, m_parametersGraphic.queryStatisticFlags));
1766
1767         const VkDeviceSize                                              vertexBufferOffset              = 0u;
1768         const de::SharedPtr<Buffer>                             vertexBufferSp                  = creatAndFillVertexBuffer();
1769         const VkBuffer                                                  vertexBuffer                    = vertexBufferSp->object();
1770
1771         const Unique<VkCommandBuffer>                   cmdBuffer                               (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1772
1773         beginCommandBuffer(vk, *cmdBuffer);
1774         {
1775                 const VkRect2D                          renderArea                              = { { 0, 0 }, { WIDTH, HEIGHT } };
1776                 std::vector<VkClearValue>       renderPassClearValues   (2);
1777                 deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1778                 const RenderPassBeginInfo       renderPassBegin                 (*m_renderPass, *m_framebuffer, renderArea, renderPassClearValues);
1779
1780                 transition2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1781                 transition2DImage(vk, *cmdBuffer, m_depthImage->object(), VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
1782
1783                 vk.cmdResetQueryPool(*cmdBuffer, *queryPool, 0u, 1u);
1784
1785                 vk.cmdBeginRenderPass(*cmdBuffer, &renderPassBegin, VK_SUBPASS_CONTENTS_INLINE);
1786
1787                 vk.cmdBeginQuery(*cmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
1788                 vk.cmdBindVertexBuffers(*cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
1789                 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1790
1791                 draw(*cmdBuffer);
1792
1793                 vk.cmdEndQuery(*cmdBuffer, *queryPool, 0u);
1794
1795                 vk.cmdEndRenderPass(*cmdBuffer);
1796
1797                 transition2DImage(vk, *cmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1798         }
1799         vk.endCommandBuffer(*cmdBuffer);
1800
1801         // Wait for completion
1802         submitCommandsAndWait(vk, device, queue, *cmdBuffer);
1803         return checkResult (*queryPool);
1804 }
1805
1806 tcu::TestStatus TessellationShaderTestInstance::checkResult (VkQueryPool queryPool)
1807 {
1808         const DeviceInterface&  vk                      = m_context.getDeviceInterface();
1809         const VkDevice                  device          = m_context.getDevice();
1810         deUint64                                result          = 0u;
1811         deUint64                                expectedMin     = 0u;
1812         deUint64                                expectedMax     = 0u;
1813         switch(m_parametersGraphic.queryStatisticFlags)
1814         {
1815                 case VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT:
1816                         expectedMin = 4u;
1817                         expectedMax = expectedMin * 4u;
1818                         break;
1819                 case VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT:
1820                         expectedMin = 100u;
1821                         expectedMax = expectedMin * 4u;
1822                         break;
1823                 default:
1824                         DE_ASSERT(0);
1825                         break;
1826         }
1827         VK_CHECK(vk.getQueryPoolResults(device, queryPool, 0u, 1u, sizeof(deUint64), &result, 0u, VK_QUERY_RESULT_64_BIT));
1828         if (result < expectedMin || result > expectedMax)
1829                 return tcu::TestStatus::fail("QueryPoolResults incorrect");
1830
1831         if (!checkImage())
1832                 return tcu::TestStatus::fail("Result image doesn't match expected image.");
1833
1834         return tcu::TestStatus::pass("Pass");
1835 }
1836
1837 void TessellationShaderTestInstance::draw (VkCommandBuffer cmdBuffer)
1838 {
1839         const DeviceInterface& vk = m_context.getDeviceInterface();
1840         vk.cmdDraw(cmdBuffer, static_cast<deUint32>(m_data.size()), 1u, 0u, 0u);
1841 }
1842
1843 class TessellationShaderSecondrayTestInstance : public TessellationShaderTestInstance
1844 {
1845 public:
1846                                                         TessellationShaderSecondrayTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic);
1847 protected:
1848         virtual tcu::TestStatus executeTest                                                             (void);
1849 };
1850
1851 TessellationShaderSecondrayTestInstance::TessellationShaderSecondrayTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic)
1852         : TessellationShaderTestInstance        (context, data, parametersGraphic)
1853 {
1854 }
1855
1856 tcu::TestStatus TessellationShaderSecondrayTestInstance::executeTest (void)
1857 {
1858         const DeviceInterface&                                  vk                                              = m_context.getDeviceInterface();
1859         const VkDevice                                                  device                                  = m_context.getDevice();
1860         const VkQueue                                                   queue                                   = m_context.getUniversalQueue();
1861         const deUint32                                                  queueFamilyIndex                = m_context.getUniversalQueueFamilyIndex();
1862
1863         const CmdPoolCreateInfo                                 cmdPoolCreateInfo               (queueFamilyIndex);
1864         const Move<VkCommandPool>                               cmdPool                                 = createCommandPool(vk, device, &cmdPoolCreateInfo);
1865         const Unique<VkQueryPool>                               queryPool                               (makeQueryPool(vk, device, m_parametersGraphic.queryStatisticFlags));
1866
1867         const VkDeviceSize                                              vertexBufferOffset              = 0u;
1868         const de::SharedPtr<Buffer>                             vertexBufferSp                  = creatAndFillVertexBuffer();
1869         const VkBuffer                                                  vertexBuffer                    = vertexBufferSp->object();
1870
1871         const Unique<VkCommandBuffer>                   primaryCmdBuffer                (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1872         const Unique<VkCommandBuffer>                   secondaryCmdBuffer              (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY));
1873
1874         beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
1875                 vk.cmdBindPipeline(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1876                 vk.cmdBeginQuery(*secondaryCmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
1877                 vk.cmdBindVertexBuffers(*secondaryCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1878                 draw(*secondaryCmdBuffer);
1879                 vk.cmdEndQuery(*secondaryCmdBuffer, *queryPool, 0u);
1880         vk.endCommandBuffer(*secondaryCmdBuffer);
1881
1882         beginCommandBuffer(vk, *primaryCmdBuffer);
1883         {
1884                 const VkRect2D                          renderArea                              = { { 0, 0 }, { WIDTH, HEIGHT } };
1885                 std::vector<VkClearValue>       renderPassClearValues   (2);
1886                 deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1887                 const RenderPassBeginInfo       renderPassBegin                 (*m_renderPass, *m_framebuffer, renderArea, renderPassClearValues);
1888
1889                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1890                 transition2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
1891
1892                 vk.cmdBindVertexBuffers(*primaryCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1893                 vk.cmdBindPipeline(*primaryCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1894                 vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, 1u);
1895
1896                 vk.cmdBeginRenderPass(*primaryCmdBuffer, &renderPassBegin, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
1897                 vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &secondaryCmdBuffer.get());
1898                 vk.cmdEndRenderPass(*primaryCmdBuffer);
1899
1900                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1901         }
1902         vk.endCommandBuffer(*primaryCmdBuffer);
1903
1904         // Wait for completion
1905         submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
1906         return checkResult (*queryPool);
1907 }
1908
1909 class TessellationShaderSecondrayInheritedTestInstance : public TessellationShaderTestInstance
1910 {
1911 public:
1912                                                         TessellationShaderSecondrayInheritedTestInstance        (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic);
1913 protected:
1914         virtual void                    checkExtensions                                                 (void);
1915         virtual tcu::TestStatus executeTest                                                             (void);
1916 };
1917
1918 TessellationShaderSecondrayInheritedTestInstance::TessellationShaderSecondrayInheritedTestInstance (vkt::Context& context, const std::vector<VertexData>& data, const ParametersGraphic& parametersGraphic)
1919         : TessellationShaderTestInstance        (context, data, parametersGraphic)
1920 {
1921 }
1922
1923 void TessellationShaderSecondrayInheritedTestInstance::checkExtensions (void)
1924 {
1925         TessellationShaderTestInstance::checkExtensions();
1926         if (!m_context.getDeviceFeatures().inheritedQueries)
1927                 throw tcu::NotSupportedError("Inherited queries are not supported");
1928 }
1929
1930 tcu::TestStatus TessellationShaderSecondrayInheritedTestInstance::executeTest (void)
1931 {
1932         const DeviceInterface&                                  vk                                              = m_context.getDeviceInterface();
1933         const VkDevice                                                  device                                  = m_context.getDevice();
1934         const VkQueue                                                   queue                                   = m_context.getUniversalQueue();
1935         const deUint32                                                  queueFamilyIndex                = m_context.getUniversalQueueFamilyIndex();
1936
1937         const CmdPoolCreateInfo                                 cmdPoolCreateInfo               (queueFamilyIndex);
1938         const Move<VkCommandPool>                               cmdPool                                 = createCommandPool(vk, device, &cmdPoolCreateInfo);
1939         const Unique<VkQueryPool>                               queryPool                               (makeQueryPool(vk, device, m_parametersGraphic.queryStatisticFlags));
1940
1941         const VkDeviceSize                                              vertexBufferOffset              = 0u;
1942         const de::SharedPtr<Buffer>                             vertexBufferSp                  = creatAndFillVertexBuffer();
1943         const VkBuffer                                                  vertexBuffer                    = vertexBufferSp->object();
1944
1945         const Unique<VkCommandBuffer>                   primaryCmdBuffer                (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
1946         const Unique<VkCommandBuffer>                   secondaryCmdBuffer              (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY));
1947
1948         beginSecondaryCommandBuffer(vk, *secondaryCmdBuffer, m_parametersGraphic.queryStatisticFlags, *m_renderPass, *m_framebuffer, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT);
1949                 vk.cmdBindPipeline(*secondaryCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1950                 vk.cmdBindVertexBuffers(*secondaryCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1951                 draw(*secondaryCmdBuffer);
1952         vk.endCommandBuffer(*secondaryCmdBuffer);
1953
1954         beginCommandBuffer(vk, *primaryCmdBuffer);
1955         {
1956                 const VkRect2D                          renderArea                              = { { 0, 0 }, { WIDTH, HEIGHT } };
1957                 std::vector<VkClearValue>       renderPassClearValues   (2);
1958                 deMemset(&renderPassClearValues[0], 0, static_cast<int>(renderPassClearValues.size()) * sizeof(VkClearValue));
1959                 const RenderPassBeginInfo       renderPassBegin                 (*m_renderPass, *m_framebuffer, renderArea, renderPassClearValues);
1960
1961                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1962                 transition2DImage(vk, *primaryCmdBuffer, m_depthImage->object(), VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
1963
1964                 vk.cmdBindVertexBuffers(*primaryCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1965                 vk.cmdBindPipeline(*primaryCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1966                 vk.cmdResetQueryPool(*primaryCmdBuffer, *queryPool, 0u, 1u);
1967                 vk.cmdBeginQuery(*primaryCmdBuffer, *queryPool, 0u, (VkQueryControlFlags)0u);
1968
1969                 vk.cmdBeginRenderPass(*primaryCmdBuffer, &renderPassBegin, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
1970                 vk.cmdExecuteCommands(*primaryCmdBuffer, 1u, &secondaryCmdBuffer.get());
1971                 vk.cmdEndRenderPass(*primaryCmdBuffer);
1972                 vk.cmdEndQuery(*primaryCmdBuffer, *queryPool, 0u);
1973
1974                 transition2DImage(vk, *primaryCmdBuffer, m_colorAttachmentImage->object(), VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1975         }
1976         vk.endCommandBuffer(*primaryCmdBuffer);
1977
1978         // Wait for completion
1979         submitCommandsAndWait(vk, device, queue, *primaryCmdBuffer);
1980         return checkResult (*queryPool);
1981 }
1982
1983 template<class Instance>
1984 class QueryPoolStatisticsTest : public TestCase
1985 {
1986 public:
1987         QueryPoolStatisticsTest (tcu::TestContext &context, const char *name, const char *description)
1988                 : TestCase                      (context, name, description)
1989         {
1990                 const tcu::UVec3        localSize[]             =
1991                 {
1992                         tcu::UVec3      (2u,                    2u,     2u),
1993                         tcu::UVec3      (1u,                    1u,     1u),
1994                         tcu::UVec3      (WIDTH/(7u*3u), 7u,     3u),
1995                 };
1996
1997                 const tcu::UVec3        groupSize[]             =
1998                 {
1999                         tcu::UVec3      (2u,                    2u,     2u),
2000                         tcu::UVec3      (WIDTH/(7u*3u), 7u,     3u),
2001                         tcu::UVec3      (1u,                    1u,     1u),
2002                 };
2003
2004                 DE_ASSERT(DE_LENGTH_OF_ARRAY(localSize) == DE_LENGTH_OF_ARRAY(groupSize));
2005
2006                 for(int shaderNdx = 0; shaderNdx < DE_LENGTH_OF_ARRAY(localSize); ++shaderNdx)
2007                 {
2008                         std::ostringstream      shaderName;
2009                         shaderName<< "compute_" << shaderNdx;
2010                         const ComputeInvocationsTestInstance::ParametersCompute prameters       =
2011                         {
2012                                 localSize[shaderNdx],
2013                                 groupSize[shaderNdx],
2014                                 shaderName.str(),
2015                         };
2016                         m_parameters.push_back(prameters);
2017                 }
2018         }
2019
2020         vkt::TestInstance* createInstance (vkt::Context& context) const
2021         {
2022                 return new Instance(context, m_parameters);
2023         }
2024
2025         void initPrograms(SourceCollections& sourceCollections) const
2026         {
2027                 std::ostringstream      source;
2028                 source  << "layout(binding = 0) writeonly buffer Output {\n"
2029                                 << "    uint values[];\n"
2030                                 << "} sb_out;\n\n"
2031                                 << "void main (void) {\n"
2032                                 << "    uvec3 indexUvec3 = uvec3 (gl_GlobalInvocationID.x,\n"
2033                                 << "                              gl_GlobalInvocationID.y * gl_NumWorkGroups.x * gl_WorkGroupSize.x,\n"
2034                                 << "                              gl_GlobalInvocationID.z * gl_NumWorkGroups.x * gl_NumWorkGroups.y * gl_WorkGroupSize.x * gl_WorkGroupSize.y);\n"
2035                                 << "    uint index = indexUvec3.x + indexUvec3.y + indexUvec3.z;\n"
2036                                 << "    sb_out.values[index] += index;\n"
2037                                 << "}\n";
2038
2039                 for(size_t shaderNdx = 0; shaderNdx < m_parameters.size(); ++shaderNdx)
2040                 {
2041                         std::ostringstream      src;
2042                         src     << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
2043                                 << "layout (local_size_x = " << m_parameters[shaderNdx].localSize.x() << ", local_size_y = " << m_parameters[shaderNdx].localSize.y() << ", local_size_z = " << m_parameters[shaderNdx].localSize.z() << ") in;\n"
2044                                 << source.str();
2045                         sourceCollections.glslSources.add(m_parameters[shaderNdx].shaderName) << glu::ComputeSource(src.str());
2046                 }
2047         }
2048 private:
2049         std::vector<ComputeInvocationsTestInstance::ParametersCompute>  m_parameters;
2050 };
2051
2052 template<class Instance>
2053 class QueryPoolGraphicStatisticsTest : public TestCase
2054 {
2055 public:
2056         QueryPoolGraphicStatisticsTest (tcu::TestContext &context, const char *name, const char *description, const GraphicBasicTestInstance::ParametersGraphic parametersGraphic)
2057                 : TestCase                              (context, name, description)
2058                 , m_parametersGraphic   (parametersGraphic)
2059         {
2060                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4(-1.0f,-1.0f, 1.0f, 1.0f), tcu::RGBA::red().toVec()));
2061                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4(-1.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::red().toVec()));
2062                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f,-1.0f, 1.0f, 1.0f), tcu::RGBA::red().toVec()));
2063                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::red().toVec()));
2064
2065                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4(-1.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
2066                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4(-1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
2067                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
2068                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
2069
2070                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f,-1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
2071                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
2072                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 1.0f,-1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
2073                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 1.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
2074
2075                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::gray().toVec()));
2076                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 0.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::gray().toVec()));
2077                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 1.0f, 0.0f, 1.0f, 1.0f), tcu::RGBA::gray().toVec()));
2078                 m_data.push_back(GraphicBasicTestInstance::VertexData(tcu::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::gray().toVec()));
2079         }
2080
2081         vkt::TestInstance* createInstance (vkt::Context& context) const
2082         {
2083                 return new Instance(context, m_data, m_parametersGraphic);
2084         }
2085
2086         void initPrograms(SourceCollections& sourceCollections) const
2087         {
2088                 { // Vertex Shader
2089                         std::ostringstream      source;
2090                         source  << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
2091                                         << "layout(location = 0) in highp vec4 in_position;\n"
2092                                         << "layout(location = 1) in vec4 in_color;\n"
2093                                         << "layout(location = 0) out vec4 out_color;\n"
2094                                         << "void main (void)\n"
2095                                         << "{\n"
2096                                         << "    gl_Position = in_position;\n"
2097                                         << "    out_color = in_color;\n"
2098                                         << "}\n";
2099                         sourceCollections.glslSources.add("vertex") << glu::VertexSource(source.str());
2100                 }
2101
2102                 if (m_parametersGraphic.queryStatisticFlags & (VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT|
2103                                                                         VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT))
2104                 {// Tessellation control & evaluation
2105                         std::ostringstream source_tc;
2106                         source_tc       << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
2107                                                 << "#extension GL_EXT_tessellation_shader : require\n"
2108                                                 << "layout(vertices = 4) out;\n"
2109                                                 << "layout(location = 0) in vec4 in_color[];\n"
2110                                                 << "layout(location = 0) out vec4 out_color[];\n"
2111                                                 << "\n"
2112                                                 << "void main (void)\n"
2113                                                 << "{\n"
2114                                                 << "    if( gl_InvocationID == 0 )\n"
2115                                                 << "    {\n"
2116                                                 << "            gl_TessLevelInner[0] = 4.0f;\n"
2117                                                 << "            gl_TessLevelInner[1] = 4.0f;\n"
2118                                                 << "            gl_TessLevelOuter[0] = 4.0f;\n"
2119                                                 << "            gl_TessLevelOuter[1] = 4.0f;\n"
2120                                                 << "            gl_TessLevelOuter[2] = 4.0f;\n"
2121                                                 << "            gl_TessLevelOuter[3] = 4.0f;\n"
2122                                                 << "    }\n"
2123                                                 << "    out_color[gl_InvocationID] = in_color[gl_InvocationID];\n"
2124                                                 << "    gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
2125                                                 << "}\n";
2126                         sourceCollections.glslSources.add("tessellation_control") << glu::TessellationControlSource(source_tc.str());
2127
2128                         std::ostringstream source_te;
2129                         source_te       << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
2130                                                 << "#extension GL_EXT_tessellation_shader : require\n"
2131                                                 << "layout( quads, equal_spacing, ccw ) in;\n"
2132                                                 << "layout(location = 0) in vec4 in_color[];\n"
2133                                                 << "layout(location = 0) out vec4 out_color;\n"
2134                                                 << "void main (void)\n"
2135                                                 << "{\n"
2136                                                 << "    const float u = gl_TessCoord.x;\n"
2137                                                 << "    const float v = gl_TessCoord.y;\n"
2138                                                 << "    const float w = gl_TessCoord.z;\n"
2139                                                 << "    gl_Position = (1 - u) * (1 - v) * gl_in[0].gl_Position +(1 - u) * v * gl_in[1].gl_Position + u * (1 - v) * gl_in[2].gl_Position + u * v * gl_in[3].gl_Position;\n"
2140                                                 << "    out_color = in_color[0];\n"
2141                                                 << "}\n";
2142                         sourceCollections.glslSources.add("tessellation_evaluation") << glu::TessellationEvaluationSource(source_te.str());
2143                 }
2144
2145                 if(m_parametersGraphic.queryStatisticFlags & (VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT | VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT |
2146                                                                         VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT | VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT))
2147                 { // Geometry Shader
2148                         std::ostringstream      source;
2149                         source  << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
2150                                         << "layout("<<inputTypeToGLString(m_parametersGraphic.primitiveTopology)<<") in;\n"
2151                                         << "layout("<<outputTypeToGLString (m_parametersGraphic.primitiveTopology)<<", max_vertices = 16) out;\n"
2152                                         << "layout(location = 0) in vec4 in_color[];\n"
2153                                         << "layout(location = 0) out vec4 out_color;\n"
2154                                         << "void main (void)\n"
2155                                         << "{\n"
2156                                         << "    out_color = in_color[0];\n"
2157                                         << "    gl_Position = gl_in[0].gl_Position;\n"
2158                                         << "    EmitVertex();\n"
2159                                         << "    EndPrimitive();\n"
2160                                         << "\n"
2161                                         << "    out_color = in_color[0];\n"
2162                                         << "    gl_Position = vec4(1.0, 1.0, 1.0, 1.0);\n"
2163                                         << "    EmitVertex();\n"
2164                                         << "    out_color = in_color[0];\n"
2165                                         << "    gl_Position = vec4(-1.0, -1.0, 1.0, 1.0);\n"
2166                                         << "    EmitVertex();\n"
2167                                         << "    EndPrimitive();\n"
2168                                         << "\n";
2169                         if (m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP ||
2170                                 m_parametersGraphic.primitiveTopology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
2171                         {
2172                                 source  << "\n"
2173                                                 << "    out_color = in_color[0];\n"
2174                                                 << "    gl_Position = gl_in[0].gl_Position;\n"
2175                                                 << "    EmitVertex();\n"
2176                                                 << "    out_color = in_color[0];\n"
2177                                                 << "    gl_Position = gl_in[1].gl_Position;\n"
2178                                                 << "    EmitVertex();\n"
2179                                                 << "    out_color = in_color[0];\n"
2180                                                 << "    gl_Position = gl_in[2].gl_Position;\n"
2181                                                 << "    EmitVertex();\n"
2182                                                 << "    out_color = in_color[0];\n"
2183                                                 << "    gl_Position = vec4(gl_in[2].gl_Position.x, gl_in[1].gl_Position.y, 1.0, 1.0);\n"
2184                                                 << "    EmitVertex();\n"
2185                                                 << "    EndPrimitive();\n";
2186                         }
2187                         else
2188                         {
2189                                 source  << "    out_color = in_color[0];\n"
2190                                                 << "    gl_Position =  vec4(1.0, 1.0, 1.0, 1.0);\n"
2191                                                 << "    EmitVertex();\n"
2192                                                 << "    out_color = in_color[0];\n"
2193                                                 << "    gl_Position = vec4(1.0, -1.0, 1.0, 1.0);\n"
2194                                                 << "    EmitVertex();\n"
2195                                                 << "    out_color = in_color[0];\n"
2196                                                 << "    gl_Position = vec4(-1.0, 1.0, 1.0, 1.0);\n"
2197                                                 << "    EmitVertex();\n"
2198                                                 << "    out_color = in_color[0];\n"
2199                                                 << "    gl_Position = vec4(-1.0, -1.0, 1.0, 1.0);\n"
2200                                                 << "    EmitVertex();\n"
2201                                                 << "    EndPrimitive();\n";
2202                         }
2203                         source  << "}\n";
2204                         sourceCollections.glslSources.add("geometry") << glu::GeometrySource(source.str());
2205                 }
2206
2207                 { // Fragment Shader
2208                         std::ostringstream      source;
2209                         source  << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
2210                                         << "layout(location = 0) in vec4 in_color;\n"
2211                                         << "layout(location = 0) out vec4 out_color;\n"
2212                                         << "void main()\n"
2213                                         <<"{\n"
2214                                         << "    out_color = in_color;\n"
2215                                         << "}\n";
2216                         sourceCollections.glslSources.add("fragment") << glu::FragmentSource(source.str());
2217                 }
2218         }
2219 private:
2220         std::vector<GraphicBasicTestInstance::VertexData>       m_data;
2221         const GraphicBasicTestInstance::ParametersGraphic       m_parametersGraphic;
2222 };
2223 } //anonymous
2224
2225 QueryPoolStatisticsTests::QueryPoolStatisticsTests (tcu::TestContext &testCtx)
2226         : TestCaseGroup(testCtx, "statistics_query", "Tests for statistics queries")
2227 {
2228 }
2229
2230 void QueryPoolStatisticsTests::init (void)
2231 {
2232         std::string topology_name [VK_PRIMITIVE_TOPOLOGY_LAST] =
2233         {
2234                 "point_list",
2235                 "line_list",
2236                 "line_strip",
2237                 "triangle_list",
2238                 "triangle_strip",
2239                 "triangle_fan",
2240                 "line_list_with_adjacency",
2241                 "line_strip_with_adjacency",
2242                 "triangle_list_with_adjacency",
2243                 "triangle_strip_with_adjacency",
2244                 "patch_list"
2245         };
2246
2247         de::MovePtr<TestCaseGroup>      computeShaderInvocationsGroup           (new TestCaseGroup(m_testCtx, "compute_shader_invocations",                     "Query pipeline statistic compute shader invocations"));
2248         de::MovePtr<TestCaseGroup>      inputAssemblyVertices                           (new TestCaseGroup(m_testCtx, "input_assembly_vertices",                        "Query pipeline statistic input assembly vertices"));
2249         de::MovePtr<TestCaseGroup>      inputAssemblyPrimitives                         (new TestCaseGroup(m_testCtx, "input_assembly_primitives",                      "Query pipeline statistic input assembly primitives"));
2250         de::MovePtr<TestCaseGroup>      vertexShaderInvocations                         (new TestCaseGroup(m_testCtx, "vertex_shader_invocations",                      "Query pipeline statistic vertex shader invocation"));
2251         de::MovePtr<TestCaseGroup>      fragmentShaderInvocations                       (new TestCaseGroup(m_testCtx, "fragment_shader_invocations",            "Query pipeline statistic fragment shader invocation"));
2252         de::MovePtr<TestCaseGroup>      geometryShaderInvocations                       (new TestCaseGroup(m_testCtx, "geometry_shader_invocations",            "Query pipeline statistic geometry shader invocation"));
2253         de::MovePtr<TestCaseGroup>      geometryShaderPrimitives                        (new TestCaseGroup(m_testCtx, "geometry_shader_primitives",                     "Query pipeline statistic geometry shader primitives"));
2254         de::MovePtr<TestCaseGroup>      clippingInvocations                                     (new TestCaseGroup(m_testCtx, "clipping_invocations",                           "Query pipeline statistic clipping invocations"));
2255         de::MovePtr<TestCaseGroup>      clippingPrimitives                                      (new TestCaseGroup(m_testCtx, "clipping_primitives",                            "Query pipeline statistic clipping primitives"));
2256         de::MovePtr<TestCaseGroup>      tesControlPatches                                       (new TestCaseGroup(m_testCtx, "tes_control_patches",                            "Query pipeline statistic tessellation control shader patches"));
2257         de::MovePtr<TestCaseGroup>      tesEvaluationShaderInvocations          (new TestCaseGroup(m_testCtx, "tes_evaluation_shader_invocations",      "Query pipeline statistic tessellation evaluation shader invocations"));
2258
2259         computeShaderInvocationsGroup->addChild(new QueryPoolStatisticsTest<ComputeInvocationsTestInstance>                                             (m_testCtx, "primary",                          ""));
2260         computeShaderInvocationsGroup->addChild(new QueryPoolStatisticsTest<ComputeInvocationsSecondaryTestInstance>                    (m_testCtx, "secondary",                        ""));
2261         computeShaderInvocationsGroup->addChild(new QueryPoolStatisticsTest<ComputeInvocationsSecondaryInheritedTestInstance>   (m_testCtx, "secondary_inherited",      ""));
2262
2263         //VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT
2264         inputAssemblyVertices->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>                                    (m_testCtx,     "primary",                              "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)));
2265         inputAssemblyVertices->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>                   (m_testCtx,     "secondary",                    "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)));
2266         inputAssemblyVertices->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>  (m_testCtx,     "secondary_inherited",  "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)));
2267
2268         //VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT
2269         {
2270                 de::MovePtr<TestCaseGroup>      primary                         (new TestCaseGroup(m_testCtx, "primary",                        ""));
2271                 de::MovePtr<TestCaseGroup>      secondary                       (new TestCaseGroup(m_testCtx, "secondary",                      ""));
2272                 de::MovePtr<TestCaseGroup>      secondaryInherited      (new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2273                 for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
2274                 {
2275                         primary->addChild                       (new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>                                   (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx)));
2276                         secondary->addChild                     (new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>                  (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx)));
2277                         secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>     (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx)));
2278                 }
2279                 inputAssemblyPrimitives->addChild(primary.release());
2280                 inputAssemblyPrimitives->addChild(secondary.release());
2281                 inputAssemblyPrimitives->addChild(secondaryInherited.release());
2282         }
2283
2284         //VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT
2285         {
2286                 de::MovePtr<TestCaseGroup>      primary                         (new TestCaseGroup(m_testCtx, "primary",                        ""));
2287                 de::MovePtr<TestCaseGroup>      secondary                       (new TestCaseGroup(m_testCtx, "secondary",                      ""));
2288                 de::MovePtr<TestCaseGroup>      secondaryInherited      (new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2289                 for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
2290                 {
2291                         primary->addChild                       (new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>                                   (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2292                         secondary->addChild                     (new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>                  (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2293                         secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>     (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2294                 }
2295                 vertexShaderInvocations->addChild(primary.release());
2296                 vertexShaderInvocations->addChild(secondary.release());
2297                 vertexShaderInvocations->addChild(secondaryInherited.release());
2298         }
2299
2300         //VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT
2301         {
2302                 de::MovePtr<TestCaseGroup>      primary                         (new TestCaseGroup(m_testCtx, "primary",                        ""));
2303                 de::MovePtr<TestCaseGroup>      secondary                       (new TestCaseGroup(m_testCtx, "secondary",                      ""));
2304                 de::MovePtr<TestCaseGroup>      secondaryInherited      (new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2305                 for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
2306                 {
2307                         primary->addChild                       (new QueryPoolGraphicStatisticsTest<VertexShaderTestInstance>                                   (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2308                         secondary->addChild                     (new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryTestInstance>                  (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2309                         secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<VertexShaderSecondaryInheritedTestInstance>     (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2310                 }
2311                 fragmentShaderInvocations->addChild(primary.release());
2312                 fragmentShaderInvocations->addChild(secondary.release());
2313                 fragmentShaderInvocations->addChild(secondaryInherited.release());
2314         }
2315
2316         //VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT
2317         {
2318                 de::MovePtr<TestCaseGroup>      primary                         (new TestCaseGroup(m_testCtx, "primary",                        ""));
2319                 de::MovePtr<TestCaseGroup>      secondary                       (new TestCaseGroup(m_testCtx, "secondary",                      ""));
2320                 de::MovePtr<TestCaseGroup>      secondaryInherited      (new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2321                 for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
2322                 {
2323                         primary->addChild                       (new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>                                         (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2324                         secondary->addChild                     (new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>                        (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2325                         secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>   (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2326                 }
2327                 geometryShaderInvocations->addChild(primary.release());
2328                 geometryShaderInvocations->addChild(secondary.release());
2329                 geometryShaderInvocations->addChild(secondaryInherited.release());
2330         }
2331
2332         //VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT
2333         {
2334                 de::MovePtr<TestCaseGroup>      primary                         (new TestCaseGroup(m_testCtx, "primary",                        ""));
2335                 de::MovePtr<TestCaseGroup>      secondary                       (new TestCaseGroup(m_testCtx, "secondary",                      ""));
2336                 de::MovePtr<TestCaseGroup>      secondaryInherited      (new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2337                 for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
2338                 {
2339                         primary->addChild                       (new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>                                         (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx)));
2340                         secondary->addChild                     (new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>                        (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx)));
2341                         secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>   (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx)));
2342                 }
2343                 geometryShaderPrimitives->addChild(primary.release());
2344                 geometryShaderPrimitives->addChild(secondary.release());
2345                 geometryShaderPrimitives->addChild(secondaryInherited.release());
2346         }
2347
2348         //VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT
2349         {
2350                 de::MovePtr<TestCaseGroup>      primary                         (new TestCaseGroup(m_testCtx, "primary",                        ""));
2351                 de::MovePtr<TestCaseGroup>      secondary                       (new TestCaseGroup(m_testCtx, "secondary",                      ""));
2352                 de::MovePtr<TestCaseGroup>      secondaryInherited      (new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2353                 for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
2354                 {
2355                         primary->addChild                       (new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>                                         (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2356                         secondary->addChild                     (new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>                        (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2357                         secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>   (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT, (VkPrimitiveTopology)topologyNdx)));
2358                 }
2359                 clippingInvocations->addChild(primary.release());
2360                 clippingInvocations->addChild(secondary.release());
2361                 clippingInvocations->addChild(secondaryInherited.release());
2362         }
2363
2364         //VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT
2365         {
2366                 de::MovePtr<TestCaseGroup>      primary                         (new TestCaseGroup(m_testCtx, "primary",                        ""));
2367                 de::MovePtr<TestCaseGroup>      secondary                       (new TestCaseGroup(m_testCtx, "secondary",                      ""));
2368                 de::MovePtr<TestCaseGroup>      secondaryInherited      (new TestCaseGroup(m_testCtx, "secondary_inherited",""));
2369                 for (int topologyNdx = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; topologyNdx < VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; ++topologyNdx)
2370                 {
2371                         primary->addChild                       (new QueryPoolGraphicStatisticsTest<GeometryShaderTestInstance>                                         (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx)));
2372                         secondary->addChild                     (new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryTestInstance>                        (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx)));
2373                         secondaryInherited->addChild(new QueryPoolGraphicStatisticsTest<GeometryShaderSecondaryInheritedTestInstance>   (m_testCtx,     topology_name[topologyNdx].c_str(),     "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT, (VkPrimitiveTopology)topologyNdx)));
2374                 }
2375                 clippingPrimitives->addChild(primary.release());
2376                 clippingPrimitives->addChild(secondary.release());
2377                 clippingPrimitives->addChild(secondaryInherited.release());
2378         }
2379
2380         //VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT
2381         tesControlPatches->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderTestInstance>                                  (m_testCtx,     "tes_control_patches",                                          "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)));
2382         tesControlPatches->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayTestInstance>                 (m_testCtx,     "tes_control_patches_secondary",                        "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)));
2383         tesControlPatches->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayInheritedTestInstance>(m_testCtx,     "tes_control_patches_secondary_inherited",      "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)));
2384
2385         //VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT
2386         tesEvaluationShaderInvocations->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderTestInstance>                                      (m_testCtx,    "tes_evaluation_shader_invocations",                                            "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)));
2387         tesEvaluationShaderInvocations->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayTestInstance>             (m_testCtx,    "tes_evaluation_shader_invocations_secondary",                          "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)));
2388         tesEvaluationShaderInvocations->addChild(new QueryPoolGraphicStatisticsTest<TessellationShaderSecondrayInheritedTestInstance>(m_testCtx,        "tes_evaluation_shader_invocations_secondary_inherited",        "",     GraphicBasicTestInstance::ParametersGraphic(VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)));
2389
2390         addChild(computeShaderInvocationsGroup.release());
2391         addChild(inputAssemblyVertices.release());
2392         addChild(inputAssemblyPrimitives.release());
2393         addChild(vertexShaderInvocations.release());
2394         addChild(fragmentShaderInvocations.release());
2395         addChild(geometryShaderInvocations.release());
2396         addChild(geometryShaderPrimitives.release());
2397         addChild(clippingInvocations.release());
2398         addChild(clippingPrimitives.release());
2399         addChild(tesControlPatches.release());
2400         addChild(tesEvaluationShaderInvocations.release());
2401 }
2402
2403 } //QueryPool
2404 } //vkt