1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 ARM Ltd.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and/or associated documentation files (the
10 * "Materials"), to deal in the Materials without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Materials, and to
13 * permit persons to whom the Materials are furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice(s) and this permission notice shall be included
17 * in all copies or substantial portions of the Materials.
19 * The Materials are Confidential Information as defined by the
20 * Khronos Membership Agreement until designated non-confidential by Khronos,
21 * at which point this condition clause shall be removed.
23 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
33 * \brief Timestamp Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktPipelineTimestampTests.hpp"
37 #include "vktPipelineClearUtil.hpp"
38 #include "vktPipelineImageUtil.hpp"
39 #include "vktPipelineVertexUtil.hpp"
40 #include "vktPipelineReferenceRenderer.hpp"
41 #include "vktTestCase.hpp"
42 #include "vktTestCaseUtil.hpp"
43 #include "vkImageUtil.hpp"
44 #include "vkMemUtil.hpp"
45 #include "vkPrograms.hpp"
46 #include "vkBuilderUtil.hpp"
47 #include "vkQueryUtil.hpp"
49 #include "vkRefUtil.hpp"
50 #include "tcuImageCompare.hpp"
51 #include "deUniquePtr.hpp"
52 #include "deStringUtil.hpp"
54 #include "vkTypeUtil.hpp"
70 typedef std::vector<VkPipelineStageFlagBits> StageFlagVector;
73 #define GEN_DESC_STRING(name,postfix) \
75 for (std::string::size_type ndx = 0; ndx<strlen(#name); ++ndx) \
76 if(isDescription && #name[ndx] == '_') \
79 desc << std::tolower(#name[ndx],loc); \
81 desc << " " << #postfix; \
83 desc << "_" << #postfix; \
84 } while (deGetFalse())
86 std::string getPipelineStageFlagStr (const VkPipelineStageFlagBits stage,
89 std::ostringstream desc;
93 #define STAGE_CASE(p) \
94 case VK_PIPELINE_STAGE_##p##_BIT: \
96 GEN_DESC_STRING(p, stage); \
99 STAGE_CASE(TOP_OF_PIPE);
100 STAGE_CASE(DRAW_INDIRECT);
101 STAGE_CASE(VERTEX_INPUT);
102 STAGE_CASE(VERTEX_SHADER);
103 STAGE_CASE(TESSELLATION_CONTROL_SHADER);
104 STAGE_CASE(TESSELLATION_EVALUATION_SHADER);
105 STAGE_CASE(GEOMETRY_SHADER);
106 STAGE_CASE(FRAGMENT_SHADER);
107 STAGE_CASE(EARLY_FRAGMENT_TESTS);
108 STAGE_CASE(LATE_FRAGMENT_TESTS);
109 STAGE_CASE(COLOR_ATTACHMENT_OUTPUT);
110 STAGE_CASE(COMPUTE_SHADER);
111 STAGE_CASE(TRANSFER);
113 STAGE_CASE(ALL_GRAPHICS);
114 STAGE_CASE(ALL_COMMANDS);
117 desc << "unknown stage!";
118 DE_FATAL("Unknown Stage!");
127 TRANSFER_METHOD_COPY_BUFFER = 0,
128 TRANSFER_METHOD_COPY_IMAGE,
129 TRANSFER_METHOD_BLIT_IMAGE,
130 TRANSFER_METHOD_COPY_BUFFER_TO_IMAGE,
131 TRANSFER_METHOD_COPY_IMAGE_TO_BUFFER,
132 TRANSFER_METHOD_UPDATE_BUFFER,
133 TRANSFER_METHOD_FILL_BUFFER,
134 TRANSFER_METHOD_CLEAR_COLOR_IMAGE,
135 TRANSFER_METHOD_CLEAR_DEPTH_STENCIL_IMAGE,
136 TRANSFER_METHOD_RESOLVE_IMAGE,
137 TRANSFER_METHOD_COPY_QUERY_POOL_RESULTS,
141 std::string getTransferMethodStr(const TransferMethod method,
144 std::ostringstream desc;
148 #define METHOD_CASE(p) \
149 case TRANSFER_METHOD_##p: \
151 GEN_DESC_STRING(p, method); \
154 METHOD_CASE(COPY_BUFFER)
155 METHOD_CASE(COPY_IMAGE)
156 METHOD_CASE(BLIT_IMAGE)
157 METHOD_CASE(COPY_BUFFER_TO_IMAGE)
158 METHOD_CASE(COPY_IMAGE_TO_BUFFER)
159 METHOD_CASE(UPDATE_BUFFER)
160 METHOD_CASE(FILL_BUFFER)
161 METHOD_CASE(CLEAR_COLOR_IMAGE)
162 METHOD_CASE(CLEAR_DEPTH_STENCIL_IMAGE)
163 METHOD_CASE(RESOLVE_IMAGE)
164 METHOD_CASE(COPY_QUERY_POOL_RESULTS)
167 desc << "unknown method!";
168 DE_FATAL("Unknown method!");
176 class TimestampTestParam
179 TimestampTestParam (const VkPipelineStageFlagBits* stages,
180 const deUint32 stageCount,
181 const bool inRenderPass);
182 ~TimestampTestParam (void);
183 virtual const std::string generateTestName (void) const;
184 virtual const std::string generateTestDescription (void) const;
185 StageFlagVector getStageVector (void) const { return m_stageVec; }
186 bool getInRenderPass (void) const { return m_inRenderPass; }
187 void toggleInRenderPass (void) { m_inRenderPass = !m_inRenderPass; }
189 StageFlagVector m_stageVec;
193 TimestampTestParam::TimestampTestParam(const VkPipelineStageFlagBits* stages,
194 const deUint32 stageCount,
195 const bool inRenderPass)
196 : m_inRenderPass(inRenderPass)
198 for (deUint32 ndx = 0; ndx < stageCount; ndx++)
200 m_stageVec.push_back(stages[ndx]);
204 TimestampTestParam::~TimestampTestParam(void)
208 const std::string TimestampTestParam::generateTestName(void) const
210 std::string result("");
212 for (StageFlagVector::const_iterator it = m_stageVec.begin(); it != m_stageVec.end(); it++)
214 if(*it != VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT)
216 result += getPipelineStageFlagStr(*it, false) + '_';
220 result += "in_render_pass";
222 result += "out_of_render_pass";
227 const std::string TimestampTestParam::generateTestDescription(void) const
229 std::string result("Record timestamp after ");
231 for (StageFlagVector::const_iterator it = m_stageVec.begin(); it != m_stageVec.end(); it++)
233 if(*it != VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT)
235 result += getPipelineStageFlagStr(*it, true) + ' ';
239 result += " in the renderpass";
241 result += " out of the render pass";
246 class TransferTimestampTestParam : public TimestampTestParam
249 TransferTimestampTestParam (const VkPipelineStageFlagBits* stages,
250 const deUint32 stageCount,
251 const bool inRenderPass,
252 const deUint32 methodNdx);
253 ~TransferTimestampTestParam (void) { }
254 const std::string generateTestName (void) const;
255 const std::string generateTestDescription (void) const;
256 TransferMethod getMethod (void) const { return m_method; }
258 TransferMethod m_method;
261 TransferTimestampTestParam::TransferTimestampTestParam(const VkPipelineStageFlagBits* stages,
262 const deUint32 stageCount,
263 const bool inRenderPass,
264 const deUint32 methodNdx)
265 : TimestampTestParam(stages, stageCount, inRenderPass)
267 DE_ASSERT(methodNdx < (deUint32)TRANSFER_METHOD_LAST);
269 m_method = (TransferMethod)methodNdx;
272 const std::string TransferTimestampTestParam::generateTestName(void) const
274 std::string result("");
276 for (StageFlagVector::const_iterator it = m_stageVec.begin(); it != m_stageVec.end(); it++)
278 if(*it != VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT)
280 result += getPipelineStageFlagStr(*it, false) + '_';
284 result += "with_" + getTransferMethodStr(m_method, false);
290 const std::string TransferTimestampTestParam::generateTestDescription(void) const
292 std::string result("");
294 for (StageFlagVector::const_iterator it = m_stageVec.begin(); it != m_stageVec.end(); it++)
296 if(*it != VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT)
298 result += getPipelineStageFlagStr(*it, true) + ' ';
302 result += "with " + getTransferMethodStr(m_method, true);
308 class SimpleGraphicsPipelineBuilder
311 SimpleGraphicsPipelineBuilder (Context& context);
312 ~SimpleGraphicsPipelineBuilder (void) { }
313 void bindShaderStage (VkShaderStageFlagBits stage,
314 const char* source_name,
315 const char* entry_name);
316 void enableTessellationStage (deUint32 patchControlPoints);
317 Move<VkPipeline> buildPipeline (tcu::UVec2 renderSize,
318 VkRenderPass renderPass);
322 VK_MAX_SHADER_STAGES = 6,
327 Move<VkShaderModule> m_shaderModules[VK_MAX_SHADER_STAGES];
328 deUint32 m_shaderStageCount;
329 VkPipelineShaderStageCreateInfo m_shaderStageInfo[VK_MAX_SHADER_STAGES];
331 deUint32 m_patchControlPoints;
333 Move<VkPipelineLayout> m_pipelineLayout;
334 Move<VkPipeline> m_graphicsPipelines;
338 SimpleGraphicsPipelineBuilder::SimpleGraphicsPipelineBuilder(Context& context)
341 m_patchControlPoints = 0;
342 m_shaderStageCount = 0;
345 void SimpleGraphicsPipelineBuilder::bindShaderStage(VkShaderStageFlagBits stage,
346 const char* source_name,
347 const char* entry_name)
349 const DeviceInterface& vk = m_context.getDeviceInterface();
350 const VkDevice vkDevice = m_context.getDevice();
352 // Create shader module
353 deUint32* pCode = (deUint32*)m_context.getBinaryCollection().get(source_name).getBinary();
354 deUint32 codeSize = (deUint32)m_context.getBinaryCollection().get(source_name).getSize();
356 const VkShaderModuleCreateInfo moduleCreateInfo =
358 VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, // VkStructureType sType;
359 DE_NULL, // const void* pNext;
360 0u, // VkShaderModuleCreateFlags flags;
361 codeSize, // deUintptr codeSize;
362 pCode, // const deUint32* pCode;
365 m_shaderModules[m_shaderStageCount] = createShaderModule(vk, vkDevice, &moduleCreateInfo);
367 // Prepare shader stage info
368 m_shaderStageInfo[m_shaderStageCount].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
369 m_shaderStageInfo[m_shaderStageCount].pNext = DE_NULL;
370 m_shaderStageInfo[m_shaderStageCount].flags = 0u;
371 m_shaderStageInfo[m_shaderStageCount].stage = stage;
372 m_shaderStageInfo[m_shaderStageCount].module = *m_shaderModules[m_shaderStageCount];
373 m_shaderStageInfo[m_shaderStageCount].pName = entry_name;
374 m_shaderStageInfo[m_shaderStageCount].pSpecializationInfo = DE_NULL;
376 m_shaderStageCount++;
379 Move<VkPipeline> SimpleGraphicsPipelineBuilder::buildPipeline(tcu::UVec2 renderSize, VkRenderPass renderPass)
381 const DeviceInterface& vk = m_context.getDeviceInterface();
382 const VkDevice vkDevice = m_context.getDevice();
384 // Create pipeline layout
386 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
388 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
389 DE_NULL, // const void* pNext;
390 0u, // VkPipelineLayoutCreateFlags flags;
391 0u, // deUint32 setLayoutCount;
392 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
393 0u, // deUint32 pushConstantRangeCount;
394 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
397 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
401 const VkVertexInputBindingDescription vertexInputBindingDescription =
403 0u, // deUint32 binding;
404 sizeof(Vertex4RGBA), // deUint32 strideInBytes;
405 VK_VERTEX_INPUT_RATE_VERTEX, // VkVertexInputRate inputRate;
408 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
411 0u, // deUint32 location;
412 0u, // deUint32 binding;
413 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
414 0u // deUint32 offsetInBytes;
417 1u, // deUint32 location;
418 0u, // deUint32 binding;
419 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
420 DE_OFFSET_OF(Vertex4RGBA, color), // deUint32 offsetInBytes;
424 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
426 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
427 DE_NULL, // const void* pNext;
428 0u, // VkPipelineVertexInputStateCreateFlags flags;
429 1u, // deUint32 vertexBindingDescriptionCount;
430 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
431 2u, // deUint32 vertexAttributeDescriptionCount;
432 vertexInputAttributeDescriptions, // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
435 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
437 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
438 DE_NULL, // const void* pNext;
439 0u, // VkPipelineInputAssemblyStateCreateFlags flags;
440 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology;
441 VK_FALSE, // VkBool32 primitiveRestartEnable;
444 const VkViewport viewport =
446 0.0f, // float originX;
447 0.0f, // float originY;
448 (float)renderSize.x(), // float width;
449 (float)renderSize.y(), // float height;
450 0.0f, // float minDepth;
451 1.0f // float maxDepth;
453 const VkRect2D scissor =
455 { 0u, 0u }, // VkOffset2D offset;
456 { renderSize.x(), renderSize.y() } // VkExtent2D extent;
458 const VkPipelineViewportStateCreateInfo viewportStateParams =
460 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
461 DE_NULL, // const void* pNext;
462 0u, // VkPipelineViewportStateCreateFlags flags;
463 1u, // deUint32 viewportCount;
464 &viewport, // const VkViewport* pViewports;
465 1u, // deUint32 scissorCount;
466 &scissor // const VkRect2D* pScissors;
469 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
471 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
472 DE_NULL, // const void* pNext;
473 0u, // VkPipelineRasterizationStateCreateFlags flags;
474 VK_FALSE, // VkBool32 depthClampEnable;
475 VK_FALSE, // VkBool32 rasterizerDiscardEnable;
476 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
477 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
478 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
479 VK_FALSE, // VkBool32 depthBiasEnable;
480 0.0f, // float depthBiasConstantFactor;
481 0.0f, // float depthBiasClamp;
482 0.0f, // float depthBiasSlopeFactor;
483 1.0f, // float lineWidth;
486 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
488 VK_FALSE, // VkBool32 blendEnable;
489 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcColorBlendFactor;
490 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstColorBlendFactor;
491 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
492 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcAlphaBlendFactor;
493 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstAlphaBlendFactor;
494 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
495 VK_COLOR_COMPONENT_R_BIT |
496 VK_COLOR_COMPONENT_G_BIT |
497 VK_COLOR_COMPONENT_B_BIT |
498 VK_COLOR_COMPONENT_A_BIT // VkColorComponentFlags colorWriteMask;
501 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
503 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
504 DE_NULL, // const void* pNext;
505 0u, // VkPipelineColorBlendStateCreateFlags flags;
506 VK_FALSE, // VkBool32 logicOpEnable;
507 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
508 1u, // deUint32 attachmentCount;
509 &colorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
510 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConst[4];
513 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
515 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
516 DE_NULL, // const void* pNext;
517 0u, // VkPipelineMultisampleStateCreateFlags flags;
518 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
519 VK_FALSE, // VkBool32 sampleShadingEnable;
520 0.0f, // float minSampleShading;
521 DE_NULL, // const VkSampleMask* pSampleMask;
522 VK_FALSE, // VkBool32 alphaToCoverageEnable;
523 VK_FALSE, // VkBool32 alphaToOneEnable;
526 const VkPipelineDynamicStateCreateInfo dynamicStateParams =
528 VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, // VkStructureType sType;
529 DE_NULL, // const void* pNext;
530 0u, // VkPipelineDynamicStateCreateFlags flags;
531 0u, // deUint32 dynamicStateCount;
532 DE_NULL, // const VkDynamicState* pDynamicStates;
535 VkPipelineDepthStencilStateCreateInfo depthStencilStateParams =
537 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
538 DE_NULL, // const void* pNext;
539 0u, // VkPipelineDepthStencilStateCreateFlags flags;
540 VK_TRUE, // VkBool32 depthTestEnable;
541 VK_TRUE, // VkBool32 depthWriteEnable;
542 VK_COMPARE_OP_LESS_OR_EQUAL, // VkCompareOp depthCompareOp;
543 VK_FALSE, // VkBool32 depthBoundsTestEnable;
544 VK_FALSE, // VkBool32 stencilTestEnable;
545 // VkStencilOpState front;
547 VK_STENCIL_OP_KEEP, // VkStencilOp failOp;
548 VK_STENCIL_OP_KEEP, // VkStencilOp passOp;
549 VK_STENCIL_OP_KEEP, // VkStencilOp depthFailOp;
550 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
551 0u, // deUint32 compareMask;
552 0u, // deUint32 writeMask;
553 0u, // deUint32 reference;
555 // VkStencilOpState back;
557 VK_STENCIL_OP_KEEP, // VkStencilOp failOp;
558 VK_STENCIL_OP_KEEP, // VkStencilOp passOp;
559 VK_STENCIL_OP_KEEP, // VkStencilOp depthFailOp;
560 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
561 0u, // deUint32 compareMask;
562 0u, // deUint32 writeMask;
563 0u, // deUint32 reference;
565 -1.0f, // float minDepthBounds;
566 +1.0f, // float maxDepthBounds;
569 const VkPipelineTessellationStateCreateInfo* pTessCreateInfo = DE_NULL;
570 if(m_patchControlPoints > 0)
572 const VkPipelineTessellationStateCreateInfo tessStateCreateInfo =
574 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, // VkStructureType sType;
575 DE_NULL, // const void* pNext;
576 0u, // VkPipelineTessellationStateCreateFlags flags;
577 m_patchControlPoints, // deUint32 patchControlPoints;
580 pTessCreateInfo = &tessStateCreateInfo;
583 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
585 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
586 DE_NULL, // const void* pNext;
587 0u, // VkPipelineCreateFlags flags;
588 m_shaderStageCount, // deUint32 stageCount;
589 m_shaderStageInfo, // const VkPipelineShaderStageCreateInfo* pStages;
590 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
591 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
592 pTessCreateInfo, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
593 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
594 &rasterStateParams, // const VkPipelineRasterizationStateCreateInfo* pRasterState;
595 &multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
596 &depthStencilStateParams, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
597 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
598 &dynamicStateParams, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
599 *m_pipelineLayout, // VkPipelineLayout layout;
600 renderPass, // VkRenderPass renderPass;
601 0u, // deUint32 subpass;
602 0u, // VkPipeline basePipelineHandle;
603 0, // deInt32 basePipelineIndex;
606 return createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
609 void SimpleGraphicsPipelineBuilder::enableTessellationStage(deUint32 patchControlPoints)
611 m_patchControlPoints = patchControlPoints;
614 template <class Test>
615 vkt::TestCase* newTestCase(tcu::TestContext& testContext,
616 TimestampTestParam* testParam)
618 return new Test(testContext,
619 testParam->generateTestName().c_str(),
620 testParam->generateTestDescription().c_str(),
625 class TimestampTest : public vkt::TestCase
633 TimestampTest(tcu::TestContext& testContext,
634 const std::string& name,
635 const std::string& description,
636 const TimestampTestParam* param)
637 : vkt::TestCase (testContext, name, description)
638 , m_stages (param->getStageVector())
639 , m_inRenderPass (param->getInRenderPass())
641 virtual ~TimestampTest (void) { }
642 virtual void initPrograms (SourceCollections& programCollection) const;
643 virtual TestInstance* createInstance (Context& context) const;
645 const StageFlagVector m_stages;
646 const bool m_inRenderPass;
649 class TimestampTestInstance : public vkt::TestInstance
652 TimestampTestInstance (Context& context,
653 const StageFlagVector& stages,
654 const bool inRenderPass);
655 virtual ~TimestampTestInstance (void);
656 virtual tcu::TestStatus iterate (void);
658 virtual tcu::TestStatus verifyTimestamp (void);
659 virtual void configCommandBuffer (void);
660 Move<VkBuffer> createBufferAndBindMemory (VkDeviceSize size,
661 VkBufferUsageFlags usage,
662 de::MovePtr<Allocation>* pAlloc);
663 Move<VkImage> createImage2DAndBindMemory (VkFormat format,
666 VkBufferUsageFlags usage,
667 VkSampleCountFlagBits sampleCount,
668 de::MovePtr<Allocation>* pAlloc);
670 const StageFlagVector m_stages;
673 Move<VkCommandPool> m_cmdPool;
674 Move<VkCommandBuffer> m_cmdBuffer;
675 Move<VkFence> m_fence;
676 Move<VkQueryPool> m_queryPool;
677 deUint64* m_timestampValues;
680 void TimestampTest::initPrograms(SourceCollections& programCollection) const
682 vkt::TestCase::initPrograms(programCollection);
685 TestInstance* TimestampTest::createInstance(Context& context) const
687 return new TimestampTestInstance(context,m_stages,m_inRenderPass);
690 TimestampTestInstance::TimestampTestInstance(Context& context,
691 const StageFlagVector& stages,
692 const bool inRenderPass)
693 : TestInstance (context)
695 , m_inRenderPass(inRenderPass)
697 const DeviceInterface& vk = context.getDeviceInterface();
698 const VkDevice vkDevice = context.getDevice();
699 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
701 // Check support for timestamp queries
703 const std::vector<VkQueueFamilyProperties> queueProperties = vk::getPhysicalDeviceQueueFamilyProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice());
705 DE_ASSERT(queueFamilyIndex < (deUint32)queueProperties.size());
707 if (!queueProperties[queueFamilyIndex].timestampValidBits)
708 throw tcu::NotSupportedError("Universal queue does not support timestamps");
713 const VkQueryPoolCreateInfo queryPoolParams =
715 VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, // VkStructureType sType;
716 DE_NULL, // const void* pNext;
717 0u, // VkQueryPoolCreateFlags flags;
718 VK_QUERY_TYPE_TIMESTAMP, // VkQueryType queryType;
719 TimestampTest::ENTRY_COUNT, // deUint32 entryCount;
720 0u, // VkQueryPipelineStatisticFlags pipelineStatistics;
723 m_queryPool = createQueryPool(vk, vkDevice, &queryPoolParams);
726 // Create command pool
728 const VkCommandPoolCreateInfo cmdPoolParams =
730 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
731 DE_NULL, // const void* pNext;
732 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCmdPoolCreateFlags flags;
733 queueFamilyIndex, // deUint32 queueFamilyIndex;
736 m_cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
739 // Create command buffer
741 const VkCommandBufferAllocateInfo cmdAllocateParams =
743 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
744 DE_NULL, // const void* pNext;
745 *m_cmdPool, // VkCommandPool cmdPool;
746 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
747 1u, // deUint32 bufferCount;
750 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdAllocateParams);
755 const VkFenceCreateInfo fenceParams =
757 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
758 DE_NULL, // const void* pNext;
759 0u, // VkFenceCreateFlags flags;
762 m_fence = createFence(vk, vkDevice, &fenceParams);
765 // alloc timestamp values
766 m_timestampValues = new deUint64[m_stages.size()];
769 TimestampTestInstance::~TimestampTestInstance(void)
771 if(m_timestampValues)
773 delete[] m_timestampValues;
774 m_timestampValues = NULL;
778 void TimestampTestInstance::configCommandBuffer(void)
780 const DeviceInterface& vk = m_context.getDeviceInterface();
782 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
784 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
785 DE_NULL, // const void* pNext;
786 0u, // VkCommandBufferUsageFlags flags;
787 (const VkCommandBufferInheritanceInfo*)DE_NULL,
790 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
792 vk.cmdResetQueryPool(*m_cmdBuffer, *m_queryPool, 0u, TimestampTest::ENTRY_COUNT);
794 deUint32 timestampEntry = 0;
795 for (StageFlagVector::const_iterator it = m_stages.begin(); it != m_stages.end(); it++)
797 vk.cmdWriteTimestamp(*m_cmdBuffer, *it, *m_queryPool, timestampEntry++);
800 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
803 tcu::TestStatus TimestampTestInstance::iterate(void)
805 const DeviceInterface& vk = m_context.getDeviceInterface();
806 const VkDevice vkDevice = m_context.getDevice();
807 const VkQueue queue = m_context.getUniversalQueue();
809 configCommandBuffer();
811 VK_CHECK(vk.resetFences(vkDevice, 1u, &m_fence.get()));
813 const VkSubmitInfo submitInfo =
815 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
816 DE_NULL, // const void* pNext;
817 0u, // deUint32 waitSemaphoreCount;
818 DE_NULL, // const VkSemaphore* pWaitSemaphores;
819 (const VkPipelineStageFlags*)DE_NULL,
820 1u, // deUint32 commandBufferCount;
821 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
822 0u, // deUint32 signalSemaphoreCount;
823 DE_NULL, // const VkSemaphore* pSignalSemaphores;
825 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *m_fence));
827 VK_CHECK(vk.waitForFences(vkDevice, 1u, &m_fence.get(), true, ~(0ull) /* infinity*/));
829 // Generate the timestamp mask
830 deUint64 timestampMask;
831 const std::vector<VkQueueFamilyProperties> queueProperties = vk::getPhysicalDeviceQueueFamilyProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice());
832 if(queueProperties[0].timestampValidBits == 0)
834 return tcu::TestStatus::fail("Device does not support timestamp!");
836 else if(queueProperties[0].timestampValidBits == 64)
838 timestampMask = 0xFFFFFFFFFFFFFFFF;
842 timestampMask = (1 << queueProperties[0].timestampValidBits) - 1u;
845 // Get timestamp value from query pool
846 deUint32 stageSize = (deUint32)m_stages.size();
848 vk.getQueryPoolResults(vkDevice, *m_queryPool, 0u, stageSize, sizeof(m_timestampValues), (void*)m_timestampValues, sizeof(deUint64), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT);
850 for (deUint32 ndx = 0; ndx < stageSize; ndx++)
852 m_timestampValues[ndx] &= timestampMask;
855 return verifyTimestamp();
858 tcu::TestStatus TimestampTestInstance::verifyTimestamp(void)
860 for (deUint32 first = 0; first < m_stages.size(); first++)
862 for (deUint32 second = 0; second < first; second++)
864 if(m_timestampValues[first] < m_timestampValues[second])
866 return tcu::TestStatus::fail("Latter stage timestamp is smaller than the former stage timestamp.");
871 return tcu::TestStatus::pass("Timestamp increases steadily.");
874 Move<VkBuffer> TimestampTestInstance::createBufferAndBindMemory(VkDeviceSize size, VkBufferUsageFlags usage, de::MovePtr<Allocation>* pAlloc)
876 const DeviceInterface& vk = m_context.getDeviceInterface();
877 const VkDevice vkDevice = m_context.getDevice();
878 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
879 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
881 const VkBufferCreateInfo vertexBufferParams =
883 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
884 DE_NULL, // const void* pNext;
885 0u, // VkBufferCreateFlags flags;
886 size, // VkDeviceSize size;
887 usage, // VkBufferUsageFlags usage;
888 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
889 1u, // deUint32 queueFamilyCount;
890 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
893 Move<VkBuffer> vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
894 de::MovePtr<Allocation> vertexBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible);
896 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferAlloc->getMemory(), vertexBufferAlloc->getOffset()));
899 *pAlloc = vertexBufferAlloc;
903 Move<VkImage> TimestampTestInstance::createImage2DAndBindMemory(VkFormat format,
906 VkBufferUsageFlags usage,
907 VkSampleCountFlagBits sampleCount,
908 de::details::MovePtr<Allocation>* pAlloc)
910 const DeviceInterface& vk = m_context.getDeviceInterface();
911 const VkDevice vkDevice = m_context.getDevice();
912 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
913 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
915 const VkImageCreateInfo colorImageParams =
917 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
918 DE_NULL, // const void* pNext;
919 0u, // VkImageCreateFlags flags;
920 VK_IMAGE_TYPE_2D, // VkImageType imageType;
921 format, // VkFormat format;
922 { width, height, 1u }, // VkExtent3D extent;
923 1u, // deUint32 mipLevels;
924 1u, // deUint32 arraySize;
925 sampleCount, // deUint32 samples;
926 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
927 usage, // VkImageUsageFlags usage;
928 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
929 1u, // deUint32 queueFamilyCount;
930 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
931 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
934 Move<VkImage> image = createImage(vk, vkDevice, &colorImageParams);
936 // Allocate and bind image memory
937 de::MovePtr<Allocation> colorImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any);
938 VK_CHECK(vk.bindImageMemory(vkDevice, *image, colorImageAlloc->getMemory(), colorImageAlloc->getOffset()));
941 *pAlloc = colorImageAlloc;
946 class BasicGraphicsTest : public TimestampTest
949 BasicGraphicsTest(tcu::TestContext& testContext,
950 const std::string& name,
951 const std::string& description,
952 const TimestampTestParam* param)
953 : TimestampTest (testContext, name, description, param)
955 virtual ~BasicGraphicsTest (void) { }
956 virtual void initPrograms (SourceCollections& programCollection) const;
957 virtual TestInstance* createInstance (Context& context) const;
960 class BasicGraphicsTestInstance : public TimestampTestInstance
965 VK_MAX_SHADER_STAGES = 6,
967 BasicGraphicsTestInstance (Context& context,
968 const StageFlagVector stages,
969 const bool inRenderPass);
970 virtual ~BasicGraphicsTestInstance (void);
972 virtual void configCommandBuffer (void);
973 virtual void buildVertexBuffer (void);
974 virtual void buildRenderPass (VkFormat colorFormat,
975 VkFormat depthFormat);
976 virtual void buildFrameBuffer (tcu::UVec2 renderSize,
977 VkFormat colorFormat,
978 VkFormat depthFormat);
980 const tcu::UVec2 m_renderSize;
981 const VkFormat m_colorFormat;
982 const VkFormat m_depthFormat;
984 Move<VkImage> m_colorImage;
985 de::MovePtr<Allocation> m_colorImageAlloc;
986 Move<VkImage> m_depthImage;
987 de::MovePtr<Allocation> m_depthImageAlloc;
988 Move<VkImageView> m_colorAttachmentView;
989 Move<VkImageView> m_depthAttachmentView;
990 Move<VkRenderPass> m_renderPass;
991 Move<VkFramebuffer> m_framebuffer;
993 Move<VkBuffer> m_vertexBuffer;
994 std::vector<Vertex4RGBA> m_vertices;
996 SimpleGraphicsPipelineBuilder m_pipelineBuilder;
997 Move<VkPipeline> m_graphicsPipelines;
1000 void BasicGraphicsTest::initPrograms (SourceCollections& programCollection) const
1002 programCollection.glslSources.add("color_vert") << glu::VertexSource(
1004 "layout(location = 0) in vec4 position;\n"
1005 "layout(location = 1) in vec4 color;\n"
1006 "layout(location = 0) out highp vec4 vtxColor;\n"
1007 "void main (void)\n"
1009 " gl_Position = position;\n"
1010 " vtxColor = color;\n"
1013 programCollection.glslSources.add("color_frag") << glu::FragmentSource(
1015 "layout(location = 0) in highp vec4 vtxColor;\n"
1016 "layout(location = 0) out highp vec4 fragColor;\n"
1017 "void main (void)\n"
1019 " fragColor = vtxColor;\n"
1023 TestInstance* BasicGraphicsTest::createInstance(Context& context) const
1025 return new BasicGraphicsTestInstance(context,m_stages,m_inRenderPass);
1028 void BasicGraphicsTestInstance::buildVertexBuffer(void)
1030 const DeviceInterface& vk = m_context.getDeviceInterface();
1031 const VkDevice vkDevice = m_context.getDevice();
1033 // Create vertex buffer
1035 de::MovePtr<Allocation> bufferAlloc;
1036 m_vertexBuffer = createBufferAndBindMemory(1024u,VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,&bufferAlloc);
1038 m_vertices = createOverlappingQuads();
1039 // Load vertices into vertex buffer
1040 deMemcpy(bufferAlloc->getHostPtr(), m_vertices.data(), m_vertices.size() * sizeof(Vertex4RGBA));
1041 flushMappedMemoryRange(vk, vkDevice, bufferAlloc->getMemory(), bufferAlloc->getOffset(), 1024u);
1045 void BasicGraphicsTestInstance::buildRenderPass(VkFormat colorFormat, VkFormat depthFormat)
1047 const DeviceInterface& vk = m_context.getDeviceInterface();
1048 const VkDevice vkDevice = m_context.getDevice();
1050 // Create render pass
1052 const VkAttachmentDescription colorAttachmentDescription =
1054 0u, // VkAttachmentDescriptionFlags flags;
1055 colorFormat, // VkFormat format;
1056 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
1057 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
1058 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
1059 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
1060 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
1061 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
1062 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout finalLayout;
1065 const VkAttachmentDescription depthAttachmentDescription =
1067 0u, // VkAttachmentDescriptionFlags flags;
1068 depthFormat, // VkFormat format;
1069 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
1070 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
1071 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp storeOp;
1072 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
1073 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
1074 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
1075 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout finalLayout;
1078 const VkAttachmentDescription attachments[2] =
1080 colorAttachmentDescription,
1081 depthAttachmentDescription
1084 const VkAttachmentReference colorAttachmentReference =
1086 0u, // deUint32 attachment;
1087 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
1090 const VkAttachmentReference depthAttachmentReference =
1092 1u, // deUint32 attachment;
1093 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL // VkImageLayout layout;
1096 const VkSubpassDescription subpassDescription =
1098 0u, // VkSubpassDescriptionFlags flags;
1099 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
1100 0u, // deUint32 inputAttachmentCount;
1101 DE_NULL, // const VkAttachmentReference* pInputAttachments;
1102 1u, // deUint32 colorAttachmentCount;
1103 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
1104 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
1105 &depthAttachmentReference, // const VkAttachmentReference* pDepthStencilAttachment;
1106 0u, // deUint32 preserveAttachmentCount;
1107 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
1110 const VkRenderPassCreateInfo renderPassParams =
1112 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
1113 DE_NULL, // const void* pNext;
1114 0u, // VkRenderPassCreateFlags flags;
1115 2u, // deUint32 attachmentCount;
1116 attachments, // const VkAttachmentDescription* pAttachments;
1117 1u, // deUint32 subpassCount;
1118 &subpassDescription, // const VkSubpassDescription* pSubpasses;
1119 0u, // deUint32 dependencyCount;
1120 DE_NULL // const VkSubpassDependency* pDependencies;
1123 m_renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
1128 void BasicGraphicsTestInstance::buildFrameBuffer(tcu::UVec2 renderSize, VkFormat colorFormat, VkFormat depthFormat)
1130 const DeviceInterface& vk = m_context.getDeviceInterface();
1131 const VkDevice vkDevice = m_context.getDevice();
1132 const VkComponentMapping ComponentMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A};
1134 // Create color image
1136 m_colorImage = createImage2DAndBindMemory(colorFormat,
1139 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
1140 VK_SAMPLE_COUNT_1_BIT,
1141 &m_colorImageAlloc);
1144 // Create depth image
1146 m_depthImage = createImage2DAndBindMemory(depthFormat,
1149 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
1150 VK_SAMPLE_COUNT_1_BIT,
1151 &m_depthImageAlloc);
1154 // Create color attachment view
1156 const VkImageViewCreateInfo colorAttachmentViewParams =
1158 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
1159 DE_NULL, // const void* pNext;
1160 0u, // VkImageViewCreateFlags flags;
1161 *m_colorImage, // VkImage image;
1162 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
1163 colorFormat, // VkFormat format;
1164 ComponentMappingRGBA, // VkComponentMapping components;
1165 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
1168 m_colorAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
1171 // Create depth attachment view
1173 const VkImageViewCreateInfo depthAttachmentViewParams =
1175 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
1176 DE_NULL, // const void* pNext;
1177 0u, // VkImageViewCreateFlags flags;
1178 *m_depthImage, // VkImage image;
1179 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
1180 depthFormat, // VkFormat format;
1181 ComponentMappingRGBA, // VkComponentMapping components;
1182 { VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
1185 m_depthAttachmentView = createImageView(vk, vkDevice, &depthAttachmentViewParams);
1188 // Create framebuffer
1190 const VkImageView attachmentBindInfos[2] =
1192 *m_colorAttachmentView,
1193 *m_depthAttachmentView,
1196 const VkFramebufferCreateInfo framebufferParams =
1198 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
1199 DE_NULL, // const void* pNext;
1200 0u, // VkFramebufferCreateFlags flags;
1201 *m_renderPass, // VkRenderPass renderPass;
1202 2u, // deUint32 attachmentCount;
1203 attachmentBindInfos, // const VkImageView* pAttachments;
1204 (deUint32)renderSize.x(), // deUint32 width;
1205 (deUint32)renderSize.y(), // deUint32 height;
1206 1u, // deUint32 layers;
1209 m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
1214 BasicGraphicsTestInstance::BasicGraphicsTestInstance(Context& context,
1215 const StageFlagVector stages,
1216 const bool inRenderPass)
1217 : TimestampTestInstance (context,stages,inRenderPass)
1218 , m_renderSize (32, 32)
1219 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
1220 , m_depthFormat (VK_FORMAT_D16_UNORM)
1221 , m_pipelineBuilder (context)
1223 buildVertexBuffer();
1225 buildRenderPass(m_colorFormat, m_depthFormat);
1227 buildFrameBuffer(m_renderSize, m_colorFormat, m_depthFormat);
1229 m_pipelineBuilder.bindShaderStage(VK_SHADER_STAGE_VERTEX_BIT, "color_vert", "main");
1230 m_pipelineBuilder.bindShaderStage(VK_SHADER_STAGE_FRAGMENT_BIT, "color_frag", "main");
1232 m_graphicsPipelines = m_pipelineBuilder.buildPipeline(m_renderSize, *m_renderPass);
1236 BasicGraphicsTestInstance::~BasicGraphicsTestInstance(void)
1240 void BasicGraphicsTestInstance::configCommandBuffer(void)
1242 const DeviceInterface& vk = m_context.getDeviceInterface();
1244 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1246 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1247 DE_NULL, // const void* pNext;
1248 0u, // VkCommandBufferUsageFlags flags;
1249 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1252 const VkClearValue attachmentClearValues[2] =
1254 defaultClearValue(m_colorFormat),
1255 defaultClearValue(m_depthFormat),
1258 const VkRenderPassBeginInfo renderPassBeginInfo =
1260 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
1261 DE_NULL, // const void* pNext;
1262 *m_renderPass, // VkRenderPass renderPass;
1263 *m_framebuffer, // VkFramebuffer framebuffer;
1264 { { 0u, 0u }, { m_renderSize.x(), m_renderSize.y() } }, // VkRect2D renderArea;
1265 2u, // deUint32 clearValueCount;
1266 attachmentClearValues // const VkClearValue* pClearValues;
1269 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1271 vk.cmdResetQueryPool(*m_cmdBuffer, *m_queryPool, 0u, TimestampTest::ENTRY_COUNT);
1273 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
1275 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_graphicsPipelines);
1276 VkDeviceSize offsets = 0u;
1277 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &m_vertexBuffer.get(), &offsets);
1278 vk.cmdDraw(*m_cmdBuffer, (deUint32)m_vertices.size(), 1u, 0u, 0u);
1282 deUint32 timestampEntry = 0u;
1283 for (StageFlagVector::const_iterator it = m_stages.begin(); it != m_stages.end(); it++)
1285 vk.cmdWriteTimestamp(*m_cmdBuffer, *it, *m_queryPool, timestampEntry++);
1289 vk.cmdEndRenderPass(*m_cmdBuffer);
1293 deUint32 timestampEntry = 0u;
1294 for (StageFlagVector::const_iterator it = m_stages.begin(); it != m_stages.end(); it++)
1296 vk.cmdWriteTimestamp(*m_cmdBuffer, *it, *m_queryPool, timestampEntry++);
1300 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1303 class AdvGraphicsTest : public BasicGraphicsTest
1306 AdvGraphicsTest (tcu::TestContext& testContext,
1307 const std::string& name,
1308 const std::string& description,
1309 const TimestampTestParam* param)
1310 : BasicGraphicsTest(testContext, name, description, param)
1312 virtual ~AdvGraphicsTest (void) { }
1313 virtual void initPrograms (SourceCollections& programCollection) const;
1314 virtual TestInstance* createInstance (Context& context) const;
1317 class AdvGraphicsTestInstance : public BasicGraphicsTestInstance
1320 AdvGraphicsTestInstance (Context& context,
1321 const StageFlagVector stages,
1322 const bool inRenderPass);
1323 virtual ~AdvGraphicsTestInstance (void);
1324 virtual void configCommandBuffer (void);
1326 virtual void featureSupportCheck (void);
1328 VkPhysicalDeviceFeatures m_features;
1329 deUint32 m_draw_count;
1330 Move<VkBuffer> m_indirectBuffer;
1333 void AdvGraphicsTest::initPrograms(SourceCollections& programCollection) const
1335 BasicGraphicsTest::initPrograms(programCollection);
1337 programCollection.glslSources.add("dummy_geo") << glu::GeometrySource(
1339 "layout (triangles) in;\n"
1340 "layout (triangle_strip, max_vertices = 3) out;\n"
1341 "void main (void)\n"
1343 " for(int ndx=0; ndx<3; ndx++)\n"
1345 " gl_Position = gl_in[ndx].gl_Position;\n"
1348 " EndPrimitive();\n"
1351 programCollection.glslSources.add("basic_tcs") << glu::TessellationControlSource(
1353 "layout(vertices = 3) out;\n"
1354 "in highp vec4 color[];\n"
1355 "out highp vec4 vtxColor[];\n"
1358 " gl_TessLevelOuter[0] = 4.0;\n"
1359 " gl_TessLevelOuter[1] = 4.0;\n"
1360 " gl_TessLevelOuter[2] = 4.0;\n"
1361 " gl_TessLevelInner[0] = 4.0;\n"
1362 " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
1363 " vtxColor[gl_InvocationID] = color[gl_InvocationID];\n"
1366 programCollection.glslSources.add("basic_tes") << glu::TessellationEvaluationSource(
1368 "layout(triangles, fractional_even_spacing, ccw) in;\n"
1369 "in highp vec4 colors[];\n"
1370 "out highp vec4 vtxColor;\n"
1373 " float u = gl_TessCoord.x;\n"
1374 " float v = gl_TessCoord.y;\n"
1375 " float w = gl_TessCoord.z;\n"
1376 " vec4 pos = vec4(0);\n"
1377 " vec4 color = vec4(0);\n"
1378 " pos.xyz += u * gl_in[0].gl_Position.xyz;\n"
1379 " color.xyz += u * colors[0].xyz;\n"
1380 " pos.xyz += v * gl_in[1].gl_Position.xyz;\n"
1381 " color.xyz += v * colors[1].xyz;\n"
1382 " pos.xyz += w * gl_in[2].gl_Position.xyz;\n"
1383 " color.xyz += w * colors[2].xyz;\n"
1386 " gl_Position = pos;\n"
1387 " vtxColor = color;\n"
1391 TestInstance* AdvGraphicsTest::createInstance(Context& context) const
1393 return new AdvGraphicsTestInstance(context,m_stages,m_inRenderPass);
1396 void AdvGraphicsTestInstance::featureSupportCheck(void)
1398 for (StageFlagVector::const_iterator it = m_stages.begin(); it != m_stages.end(); it++)
1402 case VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT:
1403 if (m_features.geometryShader == VK_FALSE)
1405 TCU_THROW(NotSupportedError, "Geometry Shader Not Supported");
1408 case VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT:
1409 case VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT:
1410 if (m_features.tessellationShader == VK_FALSE)
1412 TCU_THROW(NotSupportedError, "Tessellation Not Supported");
1415 case VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT:
1422 AdvGraphicsTestInstance::AdvGraphicsTestInstance(Context& context,
1423 const StageFlagVector stages,
1424 const bool inRenderPass)
1425 : BasicGraphicsTestInstance(context, stages, inRenderPass)
1427 m_features = m_context.getDeviceFeatures();
1429 // If necessary feature is not supported, throw error and fail current test
1430 featureSupportCheck();
1432 if(m_features.geometryShader == VK_TRUE)
1434 m_pipelineBuilder.bindShaderStage(VK_SHADER_STAGE_GEOMETRY_BIT, "dummy_geo", "main");
1437 if(m_features.tessellationShader == VK_TRUE)
1439 m_pipelineBuilder.bindShaderStage(VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, "basic_tcs", "main");
1440 m_pipelineBuilder.bindShaderStage(VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, "basic_tes", "main");
1441 m_pipelineBuilder.enableTessellationStage(3);
1444 m_graphicsPipelines = m_pipelineBuilder.buildPipeline(m_renderSize, *m_renderPass);
1446 // Prepare the indirect draw buffer
1447 const DeviceInterface& vk = m_context.getDeviceInterface();
1448 const VkDevice vkDevice = m_context.getDevice();
1450 if(m_features.multiDrawIndirect == VK_TRUE)
1458 de::MovePtr<Allocation> bufferAlloc;
1459 m_indirectBuffer = createBufferAndBindMemory(32u, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, &bufferAlloc);
1461 const VkDrawIndirectCommand indirectCmds[] =
1464 12u, // deUint32 vertexCount;
1465 1u, // deUint32 instanceCount;
1466 0u, // deUint32 firstVertex;
1467 0u, // deUint32 firstInstance;
1470 12u, // deUint32 vertexCount;
1471 1u, // deUint32 instanceCount;
1472 11u, // deUint32 firstVertex;
1473 0u, // deUint32 firstInstance;
1476 // Load data into indirect draw buffer
1477 deMemcpy(bufferAlloc->getHostPtr(), indirectCmds, m_draw_count * sizeof(VkDrawIndirectCommand));
1478 flushMappedMemoryRange(vk, vkDevice, bufferAlloc->getMemory(), bufferAlloc->getOffset(), 32u);
1482 AdvGraphicsTestInstance::~AdvGraphicsTestInstance(void)
1486 void AdvGraphicsTestInstance::configCommandBuffer(void)
1488 const DeviceInterface& vk = m_context.getDeviceInterface();
1490 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1492 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1493 DE_NULL, // const void* pNext;
1494 0u, // VkCommandBufferUsageFlags flags;
1495 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1498 const VkClearValue attachmentClearValues[2] =
1500 defaultClearValue(m_colorFormat),
1501 defaultClearValue(m_depthFormat),
1504 const VkRenderPassBeginInfo renderPassBeginInfo =
1506 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
1507 DE_NULL, // const void* pNext;
1508 *m_renderPass, // VkRenderPass renderPass;
1509 *m_framebuffer, // VkFramebuffer framebuffer;
1510 { { 0u, 0u }, { m_renderSize.x(), m_renderSize.y() } }, // VkRect2D renderArea;
1511 2u, // deUint32 clearValueCount;
1512 attachmentClearValues // const VkClearValue* pClearValues;
1515 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1517 vk.cmdResetQueryPool(*m_cmdBuffer, *m_queryPool, 0u, TimestampTest::ENTRY_COUNT);
1519 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
1521 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_graphicsPipelines);
1523 VkDeviceSize offsets = 0u;
1524 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &m_vertexBuffer.get(), &offsets);
1526 vk.cmdDrawIndirect(*m_cmdBuffer, *m_indirectBuffer, 0u, m_draw_count, sizeof(VkDrawIndirectCommand));
1530 deUint32 timestampEntry = 0u;
1531 for (StageFlagVector::const_iterator it = m_stages.begin(); it != m_stages.end(); it++)
1533 vk.cmdWriteTimestamp(*m_cmdBuffer, *it, *m_queryPool, timestampEntry++);
1537 vk.cmdEndRenderPass(*m_cmdBuffer);
1541 deUint32 timestampEntry = 0u;
1542 for (StageFlagVector::const_iterator it = m_stages.begin(); it != m_stages.end(); it++)
1544 vk.cmdWriteTimestamp(*m_cmdBuffer, *it, *m_queryPool, timestampEntry++);
1548 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1552 class BasicComputeTest : public TimestampTest
1555 BasicComputeTest (tcu::TestContext& testContext,
1556 const std::string& name,
1557 const std::string& description,
1558 const TimestampTestParam* param)
1559 : TimestampTest(testContext, name, description, param)
1561 virtual ~BasicComputeTest (void) { }
1562 virtual void initPrograms (SourceCollections& programCollection) const;
1563 virtual TestInstance* createInstance (Context& context) const;
1566 class BasicComputeTestInstance : public TimestampTestInstance
1569 BasicComputeTestInstance (Context& context,
1570 const StageFlagVector stages,
1571 const bool inRenderPass);
1572 virtual ~BasicComputeTestInstance (void);
1573 virtual void configCommandBuffer (void);
1575 Move<VkBuffer> m_inputBuf;
1576 Move<VkBuffer> m_outputBuf;
1578 Move<VkDescriptorPool> m_descriptorPool;
1579 Move<VkDescriptorSet> m_descriptorSet;
1580 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
1582 Move<VkPipelineLayout> m_pipelineLayout;
1583 Move<VkShaderModule> m_computeShaderModule;
1584 Move<VkPipeline> m_computePipelines;
1587 void BasicComputeTest::initPrograms(SourceCollections& programCollection) const
1589 TimestampTest::initPrograms(programCollection);
1591 programCollection.glslSources.add("basic_compute") << glu::ComputeSource(
1593 "layout(local_size_x = 128) in;\n"
1594 "layout(std430) buffer;\n"
1595 "layout(binding = 0) readonly buffer Input0\n"
1597 " vec4 elements[];\n"
1599 "layout(binding = 1) writeonly buffer Output\n"
1601 " vec4 elements[];\n"
1605 " uint ident = gl_GlobalInvocationID.x;\n"
1606 " output_data.elements[ident] = input_data0.elements[ident] * input_data0.elements[ident];\n"
1610 TestInstance* BasicComputeTest::createInstance(Context& context) const
1612 return new BasicComputeTestInstance(context,m_stages,m_inRenderPass);
1615 BasicComputeTestInstance::BasicComputeTestInstance(Context& context,
1616 const StageFlagVector stages,
1617 const bool inRenderPass)
1618 : TimestampTestInstance(context, stages, inRenderPass)
1620 const DeviceInterface& vk = context.getDeviceInterface();
1621 const VkDevice vkDevice = context.getDevice();
1623 // Create buffer object, allocate storage, and generate input data
1624 const VkDeviceSize size = sizeof(tcu::Vec4) * 128u;
1625 de::MovePtr<Allocation> bufferAlloc;
1626 m_inputBuf = createBufferAndBindMemory(size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, &bufferAlloc);
1627 // Load vertices into buffer
1628 tcu::Vec4* pVec = reinterpret_cast<tcu::Vec4*>(bufferAlloc->getHostPtr());
1629 for (deUint32 ndx = 0u; ndx < 128u; ndx++)
1631 for (deUint32 component = 0u; component < 4u; component++)
1633 pVec[ndx][component]= (float)(ndx * (component + 1u));
1636 flushMappedMemoryRange(vk, vkDevice, bufferAlloc->getMemory(), bufferAlloc->getOffset(), size);
1638 de::MovePtr<Allocation> dummyAlloc;
1639 m_outputBuf = createBufferAndBindMemory(size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, &dummyAlloc);
1641 std::vector<VkDescriptorBufferInfo> descriptorInfos;
1642 descriptorInfos.push_back(makeDescriptorBufferInfo(*m_inputBuf, 0u, sizeof(tcu::Vec4) * 128u));
1643 descriptorInfos.push_back(makeDescriptorBufferInfo(*m_outputBuf, 0u, sizeof(tcu::Vec4) * 128u));
1645 // Create descriptor set layout
1646 DescriptorSetLayoutBuilder descLayoutBuilder;
1648 for (deUint32 bindingNdx = 0u; bindingNdx < 2u; bindingNdx++)
1650 descLayoutBuilder.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT);
1653 m_descriptorSetLayout = descLayoutBuilder.build(vk, vkDevice);
1655 // Create descriptor pool
1656 m_descriptorPool = DescriptorPoolBuilder().addType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2).build(vk, vkDevice, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
1658 // Create descriptor set
1659 const VkDescriptorSetAllocateInfo descriptorSetAllocInfo =
1661 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
1662 DE_NULL, // const void* pNext;
1663 *m_descriptorPool, // VkDescriptorPool descriptorPool;
1664 1u, // deUint32 setLayoutCount;
1665 &m_descriptorSetLayout.get(), // const VkDescriptorSetLayout* pSetLayouts;
1667 m_descriptorSet = allocateDescriptorSet(vk, vkDevice, &descriptorSetAllocInfo);
1669 DescriptorSetUpdateBuilder builder;
1670 for (deUint32 descriptorNdx = 0u; descriptorNdx < 2u; descriptorNdx++)
1672 builder.writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(descriptorNdx), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &descriptorInfos[descriptorNdx]);
1674 builder.update(vk, vkDevice);
1676 // Create compute pipeline layout
1677 const VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo =
1679 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
1680 DE_NULL, // const void* pNext;
1681 0u, // VkPipelineLayoutCreateFlags flags;
1682 1u, // deUint32 setLayoutCount;
1683 &m_descriptorSetLayout.get(), // const VkDescriptorSetLayout* pSetLayouts;
1684 0u, // deUint32 pushConstantRangeCount;
1685 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
1688 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutCreateInfo);
1690 // Create compute shader
1691 VkShaderModuleCreateInfo shaderModuleCreateInfo =
1693 VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, // VkStructureType sType;
1694 DE_NULL, // const void* pNext;
1695 0u, // VkShaderModuleCreateFlags flags;
1696 m_context.getBinaryCollection().get("basic_compute").getSize(), // deUintptr codeSize;
1697 (deUint32*)m_context.getBinaryCollection().get("basic_compute").getBinary(), // const deUint32* pCode;
1701 m_computeShaderModule = createShaderModule(vk, vkDevice, &shaderModuleCreateInfo);
1703 // Create compute pipeline
1704 const VkPipelineShaderStageCreateInfo stageCreateInfo =
1706 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
1707 DE_NULL, // const void* pNext;
1708 0u, // VkPipelineShaderStageCreateFlags flags;
1709 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
1710 *m_computeShaderModule, // VkShaderModule module;
1711 "main", // const char* pName;
1712 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
1715 const VkComputePipelineCreateInfo pipelineCreateInfo =
1717 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
1718 DE_NULL, // const void* pNext;
1719 0u, // VkPipelineCreateFlags flags;
1720 stageCreateInfo, // VkPipelineShaderStageCreateInfo stage;
1721 *m_pipelineLayout, // VkPipelineLayout layout;
1722 (VkPipeline)0, // VkPipeline basePipelineHandle;
1723 0u, // deInt32 basePipelineIndex;
1726 m_computePipelines = createComputePipeline(vk, vkDevice, (VkPipelineCache)0u, &pipelineCreateInfo);
1730 BasicComputeTestInstance::~BasicComputeTestInstance(void)
1734 void BasicComputeTestInstance::configCommandBuffer(void)
1736 const DeviceInterface& vk = m_context.getDeviceInterface();
1738 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1740 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1741 DE_NULL, // const void* pNext;
1742 0u, // VkCmdBufferOptimizeFlags flags;
1743 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1747 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1749 vk.cmdResetQueryPool(*m_cmdBuffer, *m_queryPool, 0u, TimestampTest::ENTRY_COUNT);
1751 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *m_computePipelines);
1752 vk.cmdBindDescriptorSets(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *m_pipelineLayout, 0u, 1u, &m_descriptorSet.get(), 0u, DE_NULL);
1753 vk.cmdDispatch(*m_cmdBuffer, 128u, 1u, 1u);
1755 deUint32 timestampEntry = 0u;
1756 for (StageFlagVector::const_iterator it = m_stages.begin(); it != m_stages.end(); it++)
1758 vk.cmdWriteTimestamp(*m_cmdBuffer, *it, *m_queryPool, timestampEntry++);
1761 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1766 class TransferTest : public TimestampTest
1769 TransferTest (tcu::TestContext& testContext,
1770 const std::string& name,
1771 const std::string& description,
1772 const TimestampTestParam* param);
1773 virtual ~TransferTest (void) { }
1774 virtual void initPrograms (SourceCollections& programCollection) const;
1775 virtual TestInstance* createInstance (Context& context) const;
1777 TransferMethod m_method;
1780 class TransferTestInstance : public TimestampTestInstance
1783 TransferTestInstance (Context& context,
1784 const StageFlagVector stages,
1785 const bool inRenderPass,
1786 const TransferMethod method);
1787 virtual ~TransferTestInstance (void);
1788 virtual void configCommandBuffer (void);
1790 TransferMethod m_method;
1792 VkDeviceSize m_bufSize;
1793 Move<VkBuffer> m_srcBuffer;
1794 Move<VkBuffer> m_dstBuffer;
1796 VkFormat m_imageFormat;
1797 deUint32 m_imageWidth;
1798 deUint32 m_imageHeight;
1799 VkDeviceSize m_imageSize;
1800 Move<VkImage> m_srcImage;
1801 Move<VkImage> m_dstImage;
1802 Move<VkImage> m_depthImage;
1803 Move<VkImage> m_msImage;
1806 TransferTest::TransferTest(tcu::TestContext& testContext,
1807 const std::string& name,
1808 const std::string& description,
1809 const TimestampTestParam* param)
1810 : TimestampTest(testContext, name, description, param)
1812 const TransferTimestampTestParam* transferParam = dynamic_cast<const TransferTimestampTestParam*>(param);
1813 m_method = transferParam->getMethod();
1816 void TransferTest::initPrograms(SourceCollections& programCollection) const
1818 TimestampTest::initPrograms(programCollection);
1821 TestInstance* TransferTest::createInstance(Context& context) const
1823 return new TransferTestInstance(context, m_stages, m_inRenderPass, m_method);
1826 TransferTestInstance::TransferTestInstance(Context& context,
1827 const StageFlagVector stages,
1828 const bool inRenderPass,
1829 const TransferMethod method)
1830 : TimestampTestInstance(context, stages, inRenderPass)
1833 , m_imageFormat(VK_FORMAT_R32G32B32A32_SFLOAT)
1838 const DeviceInterface& vk = context.getDeviceInterface();
1839 const VkDevice vkDevice = context.getDevice();
1841 // Create src buffer
1842 de::MovePtr<Allocation> bufferAlloc;
1843 m_srcBuffer = createBufferAndBindMemory(m_bufSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, &bufferAlloc);
1845 // Init the source buffer memory
1846 char* pBuf = reinterpret_cast<char*>(bufferAlloc->getHostPtr());
1847 memset(pBuf, 0xFF, sizeof(char)*(size_t)m_bufSize);
1848 flushMappedMemoryRange(vk, vkDevice, bufferAlloc->getMemory(), bufferAlloc->getOffset(), m_bufSize);
1850 // Create dst buffer
1851 de::MovePtr<Allocation> dummyAlloc;
1852 m_dstBuffer = createBufferAndBindMemory(m_bufSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, &dummyAlloc);
1854 // Create src/dst/depth image
1855 m_srcImage = createImage2DAndBindMemory(m_imageFormat, m_imageWidth, m_imageHeight,
1856 VK_IMAGE_USAGE_STORAGE_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
1857 VK_SAMPLE_COUNT_1_BIT,
1859 m_dstImage = createImage2DAndBindMemory(m_imageFormat, m_imageWidth, m_imageHeight,
1860 VK_IMAGE_USAGE_STORAGE_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
1861 VK_SAMPLE_COUNT_1_BIT,
1863 m_depthImage = createImage2DAndBindMemory(VK_FORMAT_D16_UNORM, m_imageWidth, m_imageHeight,
1864 VK_IMAGE_USAGE_STORAGE_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
1865 VK_SAMPLE_COUNT_1_BIT,
1867 m_msImage = createImage2DAndBindMemory(m_imageFormat, m_imageWidth, m_imageHeight,
1868 VK_IMAGE_USAGE_STORAGE_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
1869 VK_SAMPLE_COUNT_4_BIT,
1873 TransferTestInstance::~TransferTestInstance(void)
1877 void TransferTestInstance::configCommandBuffer(void)
1879 const DeviceInterface& vk = m_context.getDeviceInterface();
1881 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1883 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1884 DE_NULL, // const void* pNext;
1885 0u, // VkCmdBufferOptimizeFlags flags;
1886 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1889 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1891 // Initialize buffer/image
1892 vk.cmdFillBuffer(*m_cmdBuffer, *m_dstBuffer, 0u, m_bufSize, 0x0);
1894 const VkClearColorValue srcClearValue =
1896 {1.0f, 1.0f, 1.0f, 1.0f}
1898 const VkClearColorValue dstClearValue =
1900 {0.0f, 0.0f, 0.0f, 0.0f}
1902 const struct VkImageSubresourceRange subRange =
1904 0u, // VkImageAspectFlags aspectMask;
1905 0u, // deUint32 baseMipLevel;
1906 1u, // deUint32 mipLevels;
1907 0u, // deUint32 baseArrayLayer;
1908 1u, // deUint32 arraySize;
1911 vk.cmdClearColorImage(*m_cmdBuffer, *m_srcImage, VK_IMAGE_LAYOUT_GENERAL, &srcClearValue, 1u, &subRange);
1912 vk.cmdClearColorImage(*m_cmdBuffer, *m_dstImage, VK_IMAGE_LAYOUT_GENERAL, &dstClearValue, 1u, &subRange);
1915 vk.cmdResetQueryPool(*m_cmdBuffer, *m_queryPool, 0u, TimestampTest::ENTRY_COUNT);
1918 const VkImageSubresourceLayers imgSubResCopy =
1920 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
1921 0u, // deUint32 mipLevel;
1922 0u, // deUint32 baseArrayLayer;
1923 1u, // deUint32 layerCount;
1926 const VkOffset3D nullOffset = {0u, 0u, 0u};
1927 const VkExtent3D imageExtent = {m_imageWidth, m_imageHeight, 1u};
1928 const VkOffset3D imageOffset = {(int)m_imageWidth, (int)m_imageHeight, 1};
1931 case TRANSFER_METHOD_COPY_BUFFER:
1933 const VkBufferCopy copyBufRegion =
1935 0u, // VkDeviceSize srcOffset;
1936 0u, // VkDeviceSize destOffset;
1937 512u, // VkDeviceSize copySize;
1939 vk.cmdCopyBuffer(*m_cmdBuffer, *m_srcBuffer, *m_dstBuffer, 1u, ©BufRegion);
1942 case TRANSFER_METHOD_COPY_IMAGE:
1944 const VkImageCopy copyImageRegion =
1946 imgSubResCopy, // VkImageSubresourceCopy srcSubresource;
1947 nullOffset, // VkOffset3D srcOffset;
1948 imgSubResCopy, // VkImageSubresourceCopy destSubresource;
1949 nullOffset, // VkOffset3D destOffset;
1950 imageExtent, // VkExtent3D extent;
1953 vk.cmdCopyImage(*m_cmdBuffer, *m_srcImage, VK_IMAGE_LAYOUT_GENERAL, *m_dstImage, VK_IMAGE_LAYOUT_GENERAL, 1u, ©ImageRegion);
1956 case TRANSFER_METHOD_COPY_BUFFER_TO_IMAGE:
1958 const VkBufferImageCopy bufImageCopy =
1960 0u, // VkDeviceSize bufferOffset;
1961 (deUint32)m_bufSize, // deUint32 bufferRowLength;
1962 (deUint32)m_imageHeight, // deUint32 bufferImageHeight;
1963 imgSubResCopy, // VkImageSubresourceCopy imageSubresource;
1964 nullOffset, // VkOffset3D imageOffset;
1965 imageExtent, // VkExtent3D imageExtent;
1967 vk.cmdCopyBufferToImage(*m_cmdBuffer, *m_srcBuffer, *m_dstImage, VK_IMAGE_LAYOUT_GENERAL, 1u, &bufImageCopy);
1970 case TRANSFER_METHOD_COPY_IMAGE_TO_BUFFER:
1972 const VkBufferImageCopy imgBufferCopy =
1974 0u, // VkDeviceSize bufferOffset;
1975 (deUint32)m_bufSize, // deUint32 bufferRowLength;
1976 (deUint32)m_imageHeight, // deUint32 bufferImageHeight;
1977 imgSubResCopy, // VkImageSubresourceCopy imageSubresource;
1978 nullOffset, // VkOffset3D imageOffset;
1979 imageExtent, // VkExtent3D imageExtent;
1981 vk.cmdCopyImageToBuffer(*m_cmdBuffer, *m_srcImage, VK_IMAGE_LAYOUT_GENERAL, *m_dstBuffer, 1u, &imgBufferCopy);
1984 case TRANSFER_METHOD_BLIT_IMAGE:
1986 const VkImageBlit imageBlt =
1988 imgSubResCopy, // VkImageSubresourceCopy srcSubresource;
1993 imgSubResCopy, // VkImageSubresourceCopy destSubresource;
1999 vk.cmdBlitImage(*m_cmdBuffer, *m_srcImage, VK_IMAGE_LAYOUT_GENERAL, *m_dstImage, VK_IMAGE_LAYOUT_GENERAL, 1u, &imageBlt, VK_FILTER_NEAREST);
2002 case TRANSFER_METHOD_CLEAR_COLOR_IMAGE:
2004 vk.cmdClearColorImage(*m_cmdBuffer, *m_dstImage, VK_IMAGE_LAYOUT_GENERAL, &srcClearValue, 1u, &subRange);
2007 case TRANSFER_METHOD_CLEAR_DEPTH_STENCIL_IMAGE:
2009 const VkClearDepthStencilValue clearDSValue =
2011 1.0f, // float depth;
2012 0u, // deUint32 stencil;
2014 vk.cmdClearDepthStencilImage(*m_cmdBuffer, *m_depthImage, VK_IMAGE_LAYOUT_GENERAL, &clearDSValue, 1u, &subRange);
2017 case TRANSFER_METHOD_FILL_BUFFER:
2019 vk.cmdFillBuffer(*m_cmdBuffer, *m_dstBuffer, 0u, m_bufSize, 0x0);
2022 case TRANSFER_METHOD_UPDATE_BUFFER:
2024 const deUint32 data[] =
2026 0xdeadbeef, 0xabcdef00, 0x12345678
2028 vk.cmdUpdateBuffer(*m_cmdBuffer, *m_dstBuffer, 0x10, sizeof(data), data);
2031 case TRANSFER_METHOD_COPY_QUERY_POOL_RESULTS:
2033 vk.cmdWriteTimestamp(*m_cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, *m_queryPool, 0u);
2034 vk.cmdCopyQueryPoolResults(*m_cmdBuffer, *m_queryPool, 0u, 1u, *m_dstBuffer, 0u, 8u, VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT);
2035 vk.cmdResetQueryPool(*m_cmdBuffer, *m_queryPool, 0u, 1u);
2038 case TRANSFER_METHOD_RESOLVE_IMAGE:
2040 const VkImageResolve imageResolve =
2042 imgSubResCopy, // VkImageSubresourceLayers srcSubresource;
2043 nullOffset, // VkOffset3D srcOffset;
2044 imgSubResCopy, // VkImageSubresourceLayers destSubresource;
2045 nullOffset, // VkOffset3D destOffset;
2046 imageExtent, // VkExtent3D extent;
2048 vk.cmdResolveImage(*m_cmdBuffer, *m_msImage, VK_IMAGE_LAYOUT_GENERAL, *m_dstImage, VK_IMAGE_LAYOUT_GENERAL, 1u, &imageResolve);
2052 DE_FATAL("Unknown Transfer Method!");
2056 deUint32 timestampEntry = 0u;
2057 for (StageFlagVector::const_iterator it = m_stages.begin(); it != m_stages.end(); it++)
2059 vk.cmdWriteTimestamp(*m_cmdBuffer, *it, *m_queryPool, timestampEntry++);
2062 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2067 tcu::TestCaseGroup* createTimestampTests (tcu::TestContext& testCtx)
2069 de::MovePtr<tcu::TestCaseGroup> timestampTests (new tcu::TestCaseGroup(testCtx, "timestamp", "timestamp tests"));
2071 // Basic Graphics Tests
2073 de::MovePtr<tcu::TestCaseGroup> basicGraphicsTests (new tcu::TestCaseGroup(testCtx, "basic_graphics_tests", "Record timestamp in different pipeline stages of basic graphics tests"));
2075 const VkPipelineStageFlagBits basicGraphicsStages0[][2] =
2077 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT},
2078 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT},
2079 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT},
2080 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT},
2081 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT},
2082 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT},
2083 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT},
2084 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT},
2086 for (deUint32 stageNdx = 0u; stageNdx < DE_LENGTH_OF_ARRAY(basicGraphicsStages0); stageNdx++)
2088 TimestampTestParam param(basicGraphicsStages0[stageNdx], 2u, true);
2089 basicGraphicsTests->addChild(newTestCase<BasicGraphicsTest>(testCtx, ¶m));
2090 param.toggleInRenderPass();
2091 basicGraphicsTests->addChild(newTestCase<BasicGraphicsTest>(testCtx, ¶m));
2094 const VkPipelineStageFlagBits basicGraphicsStages1[][3] =
2096 {VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT},
2097 {VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT},
2099 for (deUint32 stageNdx = 0u; stageNdx < DE_LENGTH_OF_ARRAY(basicGraphicsStages1); stageNdx++)
2101 TimestampTestParam param(basicGraphicsStages1[stageNdx], 3u, true);
2102 basicGraphicsTests->addChild(newTestCase<BasicGraphicsTest>(testCtx, ¶m));
2103 param.toggleInRenderPass();
2104 basicGraphicsTests->addChild(newTestCase<BasicGraphicsTest>(testCtx, ¶m));
2107 timestampTests->addChild(basicGraphicsTests.release());
2110 // Advanced Graphics Tests
2112 de::MovePtr<tcu::TestCaseGroup> advGraphicsTests (new tcu::TestCaseGroup(testCtx, "advanced_graphics_tests", "Record timestamp in different pipeline stages of advanced graphics tests"));
2114 const VkPipelineStageFlagBits advGraphicsStages[][2] =
2116 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT},
2117 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT},
2118 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT},
2119 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT},
2121 for (deUint32 stageNdx = 0u; stageNdx < DE_LENGTH_OF_ARRAY(advGraphicsStages); stageNdx++)
2123 TimestampTestParam param(advGraphicsStages[stageNdx], 2u, true);
2124 advGraphicsTests->addChild(newTestCase<AdvGraphicsTest>(testCtx, ¶m));
2125 param.toggleInRenderPass();
2126 advGraphicsTests->addChild(newTestCase<AdvGraphicsTest>(testCtx, ¶m));
2129 timestampTests->addChild(advGraphicsTests.release());
2132 // Basic Compute Tests
2134 de::MovePtr<tcu::TestCaseGroup> basicComputeTests (new tcu::TestCaseGroup(testCtx, "basic_compute_tests", "Record timestamp for computer stages"));
2136 const VkPipelineStageFlagBits basicComputeStages[][2] =
2138 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT},
2139 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT},
2141 for (deUint32 stageNdx = 0u; stageNdx < DE_LENGTH_OF_ARRAY(basicComputeStages); stageNdx++)
2143 TimestampTestParam param(basicComputeStages[stageNdx], 2u, false);
2144 basicComputeTests->addChild(newTestCase<BasicComputeTest>(testCtx, ¶m));
2147 timestampTests->addChild(basicComputeTests.release());
2152 de::MovePtr<tcu::TestCaseGroup> transferTests (new tcu::TestCaseGroup(testCtx, "transfer_tests", "Record timestamp for transfer stages"));
2154 const VkPipelineStageFlagBits transferStages[][2] =
2156 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT},
2157 {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_HOST_BIT},
2159 for (deUint32 stageNdx = 0u; stageNdx < DE_LENGTH_OF_ARRAY(transferStages); stageNdx++)
2161 for (deUint32 method = 0u; method < TRANSFER_METHOD_LAST; method++)
2163 TransferTimestampTestParam param(transferStages[stageNdx], 2u, false, method);
2164 transferTests->addChild(newTestCase<TransferTest>(testCtx, ¶m));
2168 timestampTests->addChild(transferTests.release());
2173 de::MovePtr<tcu::TestCaseGroup> miscTests (new tcu::TestCaseGroup(testCtx, "misc_tests", "Misc tests that can not be categorized to other group."));
2175 const VkPipelineStageFlagBits miscStages[] = {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT};
2176 TimestampTestParam param(miscStages, 1u, false);
2177 miscTests->addChild(new TimestampTest(testCtx,
2179 "Only write timestamp command in the commmand buffer",
2182 timestampTests->addChild(miscTests.release());
2185 return timestampTests.release();