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