1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 ARM Limited.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * \brief PushConstant Tests
23 *//*--------------------------------------------------------------------*/
25 #include "vktPipelinePushConstantTests.hpp"
26 #include "vktPipelineClearUtil.hpp"
27 #include "vktPipelineImageUtil.hpp"
28 #include "vktPipelineVertexUtil.hpp"
29 #include "vktPipelineReferenceRenderer.hpp"
30 #include "vktTestCase.hpp"
31 #include "vkImageUtil.hpp"
32 #include "vkMemUtil.hpp"
33 #include "vkPrograms.hpp"
34 #include "vkQueryUtil.hpp"
36 #include "vkRefUtil.hpp"
37 #include "vkBuilderUtil.hpp"
38 #include "vkTypeUtil.hpp"
39 #include "tcuImageCompare.hpp"
41 #include "deRandom.hpp"
42 #include "deStringUtil.hpp"
43 #include "deUniquePtr.hpp"
75 struct PushConstantData
77 struct PushConstantRange
79 VkShaderStageFlags shaderStage;
83 struct PushConstantUpdate
90 class PushConstantGraphicsTest : public vkt::TestCase
93 PushConstantGraphicsTest (tcu::TestContext& testContext,
94 const std::string& name,
95 const std::string& description,
96 const deUint32 rangeCount,
97 const PushConstantData pushConstantRange[MAX_RANGE_COUNT],
98 const deBool multipleUpdate);
99 virtual ~PushConstantGraphicsTest (void);
100 virtual void initPrograms (SourceCollections& sourceCollections) const;
101 virtual TestInstance* createInstance (Context& context) const;
102 RangeSizeCase getRangeSizeCase (deUint32 rangeSize) const;
105 const deUint32 m_rangeCount;
106 PushConstantData m_pushConstantRange[MAX_RANGE_COUNT];
107 const deBool m_multipleUpdate;
110 class PushConstantGraphicsTestInstance : public vkt::TestInstance
113 PushConstantGraphicsTestInstance (Context& context,
114 const deUint32 rangeCount,
115 const PushConstantData pushConstantRange[MAX_RANGE_COUNT],
116 const deBool multipleUpdate);
117 virtual ~PushConstantGraphicsTestInstance (void);
118 virtual tcu::TestStatus iterate (void);
120 void createShaderStage (const DeviceInterface& vk,
122 const BinaryCollection& programCollection,
124 VkShaderStageFlagBits stage,
125 Move<VkShaderModule>* module);
126 std::vector<Vertex4RGBA> createQuad (const float size);
129 tcu::TestStatus verifyImage (void);
132 const tcu::UVec2 m_renderSize;
133 const VkFormat m_colorFormat;
134 const deUint32 m_rangeCount;
135 PushConstantData m_pushConstantRange[MAX_RANGE_COUNT];
136 const deBool m_multipleUpdate;
138 VkImageCreateInfo m_colorImageCreateInfo;
139 Move<VkImage> m_colorImage;
140 de::MovePtr<Allocation> m_colorImageAlloc;
141 Move<VkImageView> m_colorAttachmentView;
142 Move<VkRenderPass> m_renderPass;
143 Move<VkFramebuffer> m_framebuffer;
145 Move<VkShaderModule> m_vertexShaderModule;
146 Move<VkShaderModule> m_fragmentShaderModule;
147 Move<VkShaderModule> m_geometryShaderModule;
148 Move<VkShaderModule> m_tessControlShaderModule;
149 Move<VkShaderModule> m_tessEvaluationShaderModule;
151 VkShaderStageFlags m_shaderFlags;
152 std::vector<VkPipelineShaderStageCreateInfo> m_shaderStage;
154 Move<VkBuffer> m_vertexBuffer;
155 std::vector<Vertex4RGBA> m_vertices;
156 de::MovePtr<Allocation> m_vertexBufferAlloc;
158 Move<VkBuffer> m_uniformBuffer;
159 de::MovePtr<Allocation> m_uniformBufferAlloc;
160 Move<VkDescriptorPool> m_descriptorPool;
161 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
162 Move<VkDescriptorSet> m_descriptorSet;
164 Move<VkPipelineLayout> m_pipelineLayout;
165 Move<VkPipeline> m_graphicsPipelines;
167 Move<VkCommandPool> m_cmdPool;
168 Move<VkCommandBuffer> m_cmdBuffer;
170 Move<VkFence> m_fence;
173 PushConstantGraphicsTest::PushConstantGraphicsTest (tcu::TestContext& testContext,
174 const std::string& name,
175 const std::string& description,
176 const deUint32 rangeCount,
177 const PushConstantData pushConstantRange[MAX_RANGE_COUNT],
178 const deBool multipleUpdate)
179 : vkt::TestCase (testContext, name, description)
180 , m_rangeCount (rangeCount)
181 , m_multipleUpdate (multipleUpdate)
183 deMemcpy(m_pushConstantRange, pushConstantRange, sizeof(PushConstantData) * MAX_RANGE_COUNT);
186 PushConstantGraphicsTest::~PushConstantGraphicsTest (void)
190 TestInstance* PushConstantGraphicsTest::createInstance (Context& context) const
192 return new PushConstantGraphicsTestInstance(context, m_rangeCount, m_pushConstantRange, m_multipleUpdate);
195 RangeSizeCase PushConstantGraphicsTest::getRangeSizeCase (deUint32 rangeSize) const
208 return SIZE_CASE_128;
210 DE_FATAL("Range size unsupported yet");
211 return SIZE_CASE_UNSUPPORTED;
215 void PushConstantGraphicsTest::initPrograms (SourceCollections& sourceCollections) const
217 std::ostringstream vertexSrc;
218 std::ostringstream fragmentSrc;
219 std::ostringstream geometrySrc;
220 std::ostringstream tessControlSrc;
221 std::ostringstream tessEvaluationSrc;
223 for (size_t rangeNdx = 0; rangeNdx < m_rangeCount; rangeNdx++)
225 if (m_pushConstantRange[rangeNdx].range.shaderStage & VK_SHADER_STAGE_VERTEX_BIT)
227 vertexSrc << "#version 450\n"
228 << "layout(location = 0) in highp vec4 position;\n"
229 << "layout(location = 1) in highp vec4 color;\n"
230 << "layout(location = 0) out highp vec4 vtxColor;\n"
231 << "out gl_PerVertex { vec4 gl_Position; };\n"
232 << "layout(push_constant) uniform Material {\n";
234 switch (getRangeSizeCase(m_pushConstantRange[rangeNdx].range.size))
237 vertexSrc << "int kind;\n"
241 vertexSrc << "vec4 color;\n"
243 << "layout(std140, binding = 0) uniform UniformBuf {\n"
245 << "} uniformBuf;\n";
248 vertexSrc << "vec4 color[2];\n"
252 vertexSrc << "int dummy1;\n"
258 vertexSrc << "vec4 color[8];\n"
262 DE_FATAL("Not implemented yet");
266 vertexSrc << "void main()\n"
268 << " gl_Position = position;\n";
270 switch (getRangeSizeCase(m_pushConstantRange[rangeNdx].range.size))
273 vertexSrc << "switch (matInst.kind) {\n"
274 << "case 0: vtxColor = vec4(0.0, 1.0, 0, 1.0); break;\n"
275 << "case 1: vtxColor = vec4(0.0, 0.0, 1.0, 1.0); break;\n"
276 << "case 2: vtxColor = vec4(1.0, 0.0, 0, 1.0); break;\n"
277 << "default: vtxColor = color; break;}\n"
281 vertexSrc << "vtxColor = (matInst.color + uniformBuf.element) * 0.5;\n"
285 vertexSrc << "vtxColor = (matInst.color[0] + matInst.color[1]) * 0.5;\n"
289 vertexSrc << "vtxColor = matInst.color;\n"
293 vertexSrc << "vec4 color = vec4(0.0, 0, 0, 0.0);\n"
294 << "for (int i = 0; i < 8; i++)\n"
296 << " color = color + matInst.color[i];\n"
298 << "vtxColor = color * 0.125;\n"
302 DE_FATAL("Not implemented yet");
306 sourceCollections.glslSources.add("color_vert") << glu::VertexSource(vertexSrc.str());
309 if (m_pushConstantRange[rangeNdx].range.shaderStage & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT)
311 tessControlSrc << "#version 450\n"
312 << "layout (vertices = 3) out;\n"
313 << "layout(push_constant) uniform TessLevel {\n"
314 << " layout(offset = 24) int level;\n"
316 << "layout(location = 0) in highp vec4 color[];\n"
317 << "layout(location = 0) out highp vec4 vtxColor[];\n"
318 << "in gl_PerVertex { vec4 gl_Position; } gl_in[gl_MaxPatchVertices];\n"
319 << "out gl_PerVertex { vec4 gl_Position; } gl_out[];\n"
322 << " gl_TessLevelInner[0] = tessLevel.level;\n"
323 << " gl_TessLevelOuter[0] = tessLevel.level;\n"
324 << " gl_TessLevelOuter[1] = tessLevel.level;\n"
325 << " gl_TessLevelOuter[2] = tessLevel.level;\n"
326 << " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
327 << " vtxColor[gl_InvocationID] = color[gl_InvocationID];\n"
330 sourceCollections.glslSources.add("color_tesc") << glu::TessellationControlSource(tessControlSrc.str());
333 if (m_pushConstantRange[rangeNdx].range.shaderStage & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)
335 tessEvaluationSrc << "#version 450\n"
336 << "layout (triangles) in;\n"
337 << "layout(push_constant) uniform Material {\n"
338 << " layout(offset = 32) vec4 color;\n"
340 << "layout(location = 0) in highp vec4 color[];\n"
341 << "layout(location = 0) out highp vec4 vtxColor;\n"
342 << "in gl_PerVertex { vec4 gl_Position; } gl_in[gl_MaxPatchVertices];\n"
343 << "out gl_PerVertex { vec4 gl_Position; };\n"
346 << " gl_Position = gl_TessCoord.x * gl_in[0].gl_Position + gl_TessCoord.y * gl_in[1].gl_Position + gl_TessCoord.z * gl_in[2].gl_Position;\n"
347 << " vtxColor = matInst.color;\n"
350 sourceCollections.glslSources.add("color_tese") << glu::TessellationEvaluationSource(tessEvaluationSrc.str());
353 if (m_pushConstantRange[rangeNdx].range.shaderStage & VK_SHADER_STAGE_GEOMETRY_BIT)
355 geometrySrc << "#version 450\n"
356 << "layout(triangles) in;\n"
357 << "layout(triangle_strip, max_vertices=3) out;\n"
358 << "layout(push_constant) uniform Material {\n"
359 << " layout(offset = 20) int kind;\n"
361 << "layout(location = 0) in highp vec4 color[];\n"
362 << "layout(location = 0) out highp vec4 vtxColor;\n"
363 << "in gl_PerVertex { vec4 gl_Position; } gl_in[];\n"
364 << "out gl_PerVertex { vec4 gl_Position; };\n"
367 << " for(int i=0; i<3; i++)\n"
369 << " gl_Position.xyz = gl_in[i].gl_Position.xyz / matInst.kind;\n"
370 << " gl_Position.w = gl_in[i].gl_Position.w;\n"
371 << " vtxColor = color[i];\n"
372 << " EmitVertex();\n"
374 << " EndPrimitive();\n"
377 sourceCollections.glslSources.add("color_geom") << glu::GeometrySource(geometrySrc.str());
380 if (m_pushConstantRange[rangeNdx].range.shaderStage & VK_SHADER_STAGE_FRAGMENT_BIT)
382 fragmentSrc << "#version 450\n"
383 << "layout(location = 0) in highp vec4 vtxColor;\n"
384 << "layout(location = 0) out highp vec4 fragColor;\n"
385 << "layout(push_constant) uniform Material {\n";
387 if (m_pushConstantRange[rangeNdx].range.shaderStage & VK_SHADER_STAGE_VERTEX_BIT)
389 fragmentSrc << " layout(offset = 0) int kind;\n"
394 fragmentSrc << " layout(offset = 16) int kind;\n"
398 fragmentSrc << "void main (void)\n"
400 << " switch (matInst.kind) {\n"
401 << " case 0: fragColor = vec4(0, 1.0, 0, 1.0); break;\n"
402 << " case 1: fragColor = vec4(0, 0.0, 1.0, 1.0); break;\n"
403 << " case 2: fragColor = vtxColor; break;\n"
404 << " default: fragColor = vec4(1.0, 1.0, 1.0, 1.0); break;}\n"
407 sourceCollections.glslSources.add("color_frag") << glu::FragmentSource(fragmentSrc.str());
411 // add a pass through fragment shader if it's not activated in push constant ranges
412 if (fragmentSrc.str().empty())
414 fragmentSrc << "#version 450\n"
415 << "layout(location = 0) in highp vec4 vtxColor;\n"
416 << "layout(location = 0) out highp vec4 fragColor;\n"
417 << "void main (void)\n"
419 << " fragColor = vtxColor;\n"
422 sourceCollections.glslSources.add("color_frag") << glu::FragmentSource(fragmentSrc.str());
426 void PushConstantGraphicsTestInstance::createShaderStage (const DeviceInterface& vk,
428 const BinaryCollection& programCollection,
430 VkShaderStageFlagBits stage,
431 Move<VkShaderModule>* module)
433 *module = createShaderModule(vk, device, programCollection.get(name), 0);
435 const vk::VkPipelineShaderStageCreateInfo stageCreateInfo =
437 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
438 DE_NULL, // const void* pNext;
439 0u, // VkPipelineShaderStageCreateFlags flags;
440 stage, // VkShaderStageFlagBits stage;
441 **module, // VkShaderModule module;
442 "main", // const char* pName;
443 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
446 m_shaderStage.push_back(stageCreateInfo);
449 std::vector<Vertex4RGBA> PushConstantGraphicsTestInstance::createQuad(const float size)
451 std::vector<Vertex4RGBA> vertices;
453 const tcu::Vec4 color = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
454 const Vertex4RGBA lowerLeftVertex = {tcu::Vec4(-size, -size, 0.0f, 1.0f), color};
455 const Vertex4RGBA lowerRightVertex = {tcu::Vec4(size, -size, 0.0f, 1.0f), color};
456 const Vertex4RGBA UpperLeftVertex = {tcu::Vec4(-size, size, 0.0f, 1.0f), color};
457 const Vertex4RGBA UpperRightVertex = {tcu::Vec4(size, size, 0.0f, 1.0f), color};
459 vertices.push_back(lowerLeftVertex);
460 vertices.push_back(lowerRightVertex);
461 vertices.push_back(UpperLeftVertex);
462 vertices.push_back(UpperLeftVertex);
463 vertices.push_back(lowerRightVertex);
464 vertices.push_back(UpperRightVertex);
469 PushConstantGraphicsTestInstance::PushConstantGraphicsTestInstance (Context& context,
470 const deUint32 rangeCount,
471 const PushConstantData pushConstantRange[MAX_RANGE_COUNT],
472 deBool multipleUpdate)
473 : vkt::TestInstance (context)
474 , m_renderSize (32, 32)
475 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
476 , m_rangeCount (rangeCount)
477 , m_multipleUpdate (multipleUpdate)
478 , m_shaderFlags (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT)
480 const DeviceInterface& vk = context.getDeviceInterface();
481 const VkDevice vkDevice = context.getDevice();
482 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
483 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
484 const VkComponentMapping componentMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
486 deMemcpy(m_pushConstantRange, pushConstantRange, sizeof(PushConstantData) * MAX_RANGE_COUNT);
488 // Create color image
490 const VkImageCreateInfo colorImageParams =
492 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
493 DE_NULL, // const void* pNext;
494 0u, // VkImageCreateFlags flags;
495 VK_IMAGE_TYPE_2D, // VkImageType imageType;
496 m_colorFormat, // VkFormat format;
497 { m_renderSize.x(), m_renderSize.y(), 1u }, // VkExtent3D extent;
498 1u, // deUint32 mipLevels;
499 1u, // deUint32 arrayLayers;
500 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
501 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
502 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
503 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
504 1u, // deUint32 queueFamilyIndexCount;
505 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
506 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
509 m_colorImageCreateInfo = colorImageParams;
510 m_colorImage = createImage(vk, vkDevice, &m_colorImageCreateInfo);
512 // Allocate and bind color image memory
513 m_colorImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_colorImage), MemoryRequirement::Any);
514 VK_CHECK(vk.bindImageMemory(vkDevice, *m_colorImage, m_colorImageAlloc->getMemory(), m_colorImageAlloc->getOffset()));
517 // Create color attachment view
519 const VkImageViewCreateInfo colorAttachmentViewParams =
521 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
522 DE_NULL, // const void* pNext;
523 0u, // VkImageViewCreateFlags flags;
524 *m_colorImage, // VkImage image;
525 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
526 m_colorFormat, // VkFormat format;
527 componentMappingRGBA, // VkChannelMapping channels;
528 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
531 m_colorAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
534 // Create render pass
536 const VkAttachmentDescription colorAttachmentDescription =
538 0u, // VkAttachmentDescriptionFlags flags;
539 m_colorFormat, // VkFormat format;
540 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
541 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
542 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
543 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
544 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
545 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
546 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
549 const VkAttachmentDescription attachments[1] =
551 colorAttachmentDescription
554 const VkAttachmentReference colorAttachmentReference =
556 0u, // deUint32 attachment;
557 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
560 const VkAttachmentReference depthAttachmentReference =
562 VK_ATTACHMENT_UNUSED, // deUint32 attachment;
563 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout layout;
566 const VkSubpassDescription subpassDescription =
568 0u, // VkSubpassDescriptionFlags flags;
569 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
570 0u, // deUint32 inputAttachmentCount;
571 DE_NULL, // const VkAttachmentReference* pInputAttachments;
572 1u, // deUint32 colorAttachmentCount;
573 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
574 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
575 &depthAttachmentReference, // const VkAttachmentReference* pDepthStencilAttachment;
576 0u, // deUint32 preserveAttachmentCount;
577 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
580 const VkRenderPassCreateInfo renderPassParams =
582 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
583 DE_NULL, // const void* pNext;
584 0u, // VkRenderPassCreateFlags flags;
585 1u, // deUint32 attachmentCount;
586 attachments, // const VkAttachmentDescription* pAttachments;
587 1u, // deUint32 subpassCount;
588 &subpassDescription, // const VkSubpassDescription* pSubpasses;
589 0u, // deUint32 dependencyCount;
590 DE_NULL // const VkSubpassDependency* pDependencies;
593 m_renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
596 // Create framebuffer
598 const VkImageView attachmentBindInfos[1] =
600 *m_colorAttachmentView
603 const VkFramebufferCreateInfo framebufferParams =
605 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
606 DE_NULL, // const void* pNext;
607 0u, // VkFramebufferCreateFlags flags;
608 *m_renderPass, // VkRenderPass renderPass;
609 1u, // deUint32 attachmentCount;
610 attachmentBindInfos, // const VkImageView* pAttachments;
611 (deUint32)m_renderSize.x(), // deUint32 width;
612 (deUint32)m_renderSize.y(), // deUint32 height;
613 1u // deUint32 layers;
616 m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
619 // Create pipeline layout
621 // create push constant range
622 VkPushConstantRange pushConstantRanges[MAX_RANGE_COUNT];
623 for (size_t rangeNdx = 0; rangeNdx < m_rangeCount; rangeNdx++)
625 pushConstantRanges[rangeNdx].stageFlags = m_pushConstantRange[rangeNdx].range.shaderStage;
626 pushConstantRanges[rangeNdx].offset = m_pushConstantRange[rangeNdx].range.offset;
627 pushConstantRanges[rangeNdx].size = m_pushConstantRange[rangeNdx].range.size;
630 // create descriptor set layout
631 m_descriptorSetLayout = DescriptorSetLayoutBuilder().addSingleBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT).build(vk, vkDevice);
633 // create descriptor pool
634 m_descriptorPool = DescriptorPoolBuilder().addType(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1u).build(vk, vkDevice, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
636 // create uniform buffer
637 const VkBufferCreateInfo uniformBufferCreateInfo =
639 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
640 DE_NULL, // const void* pNext;
641 0u, // VkBufferCreateFlags flags
642 16u, // VkDeviceSize size;
643 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, // VkBufferUsageFlags usage;
644 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
645 1u, // deUint32 queueFamilyCount;
646 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
649 m_uniformBuffer = createBuffer(vk, vkDevice, &uniformBufferCreateInfo);
650 m_uniformBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_uniformBuffer), MemoryRequirement::HostVisible);
651 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_uniformBuffer, m_uniformBufferAlloc->getMemory(), m_uniformBufferAlloc->getOffset()));
653 tcu::Vec4 value = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
654 deMemcpy(m_uniformBufferAlloc->getHostPtr(), &value, 16u);
655 flushMappedMemoryRange(vk, vkDevice, m_uniformBufferAlloc->getMemory(), m_uniformBufferAlloc->getOffset(), 16u);
657 // create and update descriptor set
658 const VkDescriptorSetAllocateInfo allocInfo =
660 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
661 DE_NULL, // const void* pNext;
662 *m_descriptorPool, // VkDescriptorPool descriptorPool;
663 1u, // uint32_t setLayoutCount;
664 &(*m_descriptorSetLayout), // const VkDescriptorSetLayout* pSetLayouts;
666 m_descriptorSet = allocateDescriptorSet(vk, vkDevice, &allocInfo);
668 const VkDescriptorBufferInfo descriptorInfo = makeDescriptorBufferInfo(*m_uniformBuffer, (VkDeviceSize)0u, (VkDeviceSize)16u);
670 DescriptorSetUpdateBuilder()
671 .writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &descriptorInfo)
672 .update(vk, vkDevice);
674 // create pipeline layout
675 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
677 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
678 DE_NULL, // const void* pNext;
679 0u, // VkPipelineLayoutCreateFlags flags;
680 1u, // deUint32 descriptorSetCount;
681 &(*m_descriptorSetLayout), // const VkDescriptorSetLayout* pSetLayouts;
682 m_rangeCount, // deUint32 pushConstantRangeCount;
683 pushConstantRanges // const VkPushConstantRange* pPushConstantRanges;
686 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
691 for (size_t rangeNdx = 0; rangeNdx < m_rangeCount; rangeNdx++)
693 if (m_pushConstantRange[rangeNdx].range.shaderStage & VK_SHADER_STAGE_GEOMETRY_BIT)
695 m_shaderFlags |= VK_SHADER_STAGE_GEOMETRY_BIT;
697 if (m_pushConstantRange[rangeNdx].range.shaderStage & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT)
699 m_shaderFlags |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
701 if (m_pushConstantRange[rangeNdx].range.shaderStage & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)
703 m_shaderFlags |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
707 VkPhysicalDeviceFeatures features = m_context.getDeviceFeatures();
709 createShaderStage(vk, vkDevice, m_context.getBinaryCollection(), "color_vert", VK_SHADER_STAGE_VERTEX_BIT , &m_vertexShaderModule);
710 if (m_shaderFlags & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT || m_shaderFlags & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT)
712 if (features.tessellationShader == VK_FALSE)
714 TCU_THROW(NotSupportedError, "Tessellation Not Supported");
716 createShaderStage(vk, vkDevice, m_context.getBinaryCollection(), "color_tesc", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, &m_tessControlShaderModule);
717 createShaderStage(vk, vkDevice, m_context.getBinaryCollection(), "color_tese", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, &m_tessEvaluationShaderModule);
719 if (m_shaderFlags & VK_SHADER_STAGE_GEOMETRY_BIT)
721 if (features.geometryShader == VK_FALSE)
723 TCU_THROW(NotSupportedError, "Geometry Not Supported");
725 createShaderStage(vk, vkDevice, m_context.getBinaryCollection(), "color_geom", VK_SHADER_STAGE_GEOMETRY_BIT, &m_geometryShaderModule);
727 createShaderStage(vk, vkDevice, m_context.getBinaryCollection(), "color_frag", VK_SHADER_STAGE_FRAGMENT_BIT, &m_fragmentShaderModule);
732 const VkVertexInputBindingDescription vertexInputBindingDescription =
734 0u, // deUint32 binding;
735 sizeof(Vertex4RGBA), // deUint32 strideInBytes;
736 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputStepRate stepRate;
739 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] =
742 0u, // deUint32 location;
743 0u, // deUint32 binding;
744 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
745 0u // deUint32 offsetInBytes;
748 1u, // deUint32 location;
749 0u, // deUint32 binding;
750 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
751 DE_OFFSET_OF(Vertex4RGBA, color), // deUint32 offset;
755 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
757 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
758 DE_NULL, // const void* pNext;
759 0u, // vkPipelineVertexInputStateCreateFlags flags;
760 1u, // deUint32 bindingCount;
761 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
762 2u, // deUint32 attributeCount;
763 vertexInputAttributeDescriptions // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
766 const VkPrimitiveTopology topology = (m_shaderFlags & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) ? VK_PRIMITIVE_TOPOLOGY_PATCH_LIST : VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
767 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
769 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
770 DE_NULL, // const void* pNext;
771 (VkPipelineInputAssemblyStateCreateFlags)0u, // VkPipelineInputAssemblyStateCreateFlags flags;
772 topology, // VkPrimitiveTopology topology;
773 false // VkBool32 primitiveRestartEnable;
776 const VkViewport viewport =
778 0.0f, // float originX;
779 0.0f, // float originY;
780 (float)m_renderSize.x(), // float width;
781 (float)m_renderSize.y(), // float height;
782 0.0f, // float minDepth;
783 1.0f // float maxDepth;
786 const VkRect2D scissor = { { 0, 0 }, { m_renderSize.x(), m_renderSize.y() } };
788 const VkPipelineViewportStateCreateInfo viewportStateParams =
790 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
791 DE_NULL, // const void* pNext;
792 (VkPipelineViewportStateCreateFlags)0u, // VkPipelineViewportStateCreateFlags flags;
793 1u, // deUint32 viewportCount;
794 &viewport, // const VkViewport* pViewports;
795 1u, // deUint32 scissorCount;
796 &scissor, // const VkRect2D* pScissors;
799 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
801 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
802 DE_NULL, // const void* pNext;
803 0u, // VkPipelineRasterizationStateCreateFlags flags;
804 false, // VkBool32 depthClampEnable;
805 false, // VkBool32 rasterizerDiscardEnable;
806 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
807 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
808 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
809 VK_FALSE, // VkBool32 depthBiasEnable;
810 0.0f, // float depthBiasConstantFactor;
811 0.0f, // float depthBiasClamp;
812 0.0f, // float depthBiasSlopeFactor;
813 1.0f, // float lineWidth;
816 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
818 false, // VkBool32 blendEnable;
819 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcColorBlendFactor;
820 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstColorBlendFactor;
821 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
822 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcAlphaBlendFactor;
823 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstAlphaBlendFactor;
824 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
825 VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | // VkColorComponentFlags colorWriteMask;
826 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
829 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
831 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
832 DE_NULL, // const void* pNext;
833 0, // VkPipelineColorBlendStateCreateFlags flags;
834 false, // VkBool32 logicOpEnable;
835 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
836 1u, // deUint32 attachmentCount;
837 &colorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
838 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConstants[4];
841 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
843 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
844 DE_NULL, // const void* pNext;
845 0u, // VkPipelineMultisampleStateCreateFlags flags;
846 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
847 false, // VkBool32 sampleShadingEnable;
848 0.0f, // float minSampleShading;
849 DE_NULL, // const VkSampleMask* pSampleMask;
850 false, // VkBool32 alphaToCoverageEnable;
851 false // VkBool32 alphaToOneEnable;
854 VkPipelineDepthStencilStateCreateInfo depthStencilStateParams =
856 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
857 DE_NULL, // const void* pNext;
858 0u, // VkPipelineDepthStencilStateCreateFlags flags;
859 false, // VkBool32 depthTestEnable;
860 false, // VkBool32 depthWriteEnable;
861 VK_COMPARE_OP_LESS, // VkCompareOp depthCompareOp;
862 false, // VkBool32 depthBoundsTestEnable;
863 false, // VkBool32 stencilTestEnable;
864 // VkStencilOpState front;
866 VK_STENCIL_OP_KEEP, // VkStencilOp stencilFailOp;
867 VK_STENCIL_OP_KEEP, // VkStencilOp stencilPassOp;
868 VK_STENCIL_OP_KEEP, // VkStencilOp stencilDepthFailOp;
869 VK_COMPARE_OP_NEVER, // VkCompareOp stencilCompareOp;
870 0u, // deUint32 stencilCompareMask;
871 0u, // deUint32 stencilWriteMask;
872 0u, // deUint32 stencilReference;
874 // VkStencilOpState back;
876 VK_STENCIL_OP_KEEP, // VkStencilOp stencilFailOp;
877 VK_STENCIL_OP_KEEP, // VkStencilOp stencilPassOp;
878 VK_STENCIL_OP_KEEP, // VkStencilOp stencilDepthFailOp;
879 VK_COMPARE_OP_NEVER, // VkCompareOp stencilCompareOp;
880 0u, // deUint32 stencilCompareMask;
881 0u, // deUint32 stencilWriteMask;
882 0u, // deUint32 stencilReference;
884 0.0f, // float minDepthBounds;
885 1.0f, // float maxDepthBounds;
888 const VkPipelineTessellationStateCreateInfo tessellationStateParams =
890 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, // VkStructureType sType;
891 DE_NULL, // const void* pNext;
892 0u, // VkPipelineTessellationStateCreateFlags flags;
893 3u, // uint32_t patchControlPoints;
896 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
898 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
899 DE_NULL, // const void* pNext;
900 0u, // VkPipelineCreateFlags flags;
901 (deUint32)m_shaderStage.size(), // deUint32 stageCount;
902 &m_shaderStage[0], // const VkPipelineShaderStageCreateInfo* pStages;
903 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
904 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
905 (m_shaderFlags & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT ? &tessellationStateParams: DE_NULL), // const VkPipelineTessellationStateCreateInfo* pTessellationState;
906 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
907 &rasterStateParams, // const VkPipelineRasterStateCreateInfo* pRasterState;
908 &multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
909 &depthStencilStateParams, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
910 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
911 (const VkPipelineDynamicStateCreateInfo*)DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
912 *m_pipelineLayout, // VkPipelineLayout layout;
913 *m_renderPass, // VkRenderPass renderPass;
914 0u, // deUint32 subpass;
915 0u, // VkPipeline basePipelineHandle;
916 0u // deInt32 basePipelineIndex;
919 m_graphicsPipelines = createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
922 // Create vertex buffer
924 m_vertices = createQuad(1.0f);
926 const VkBufferCreateInfo vertexBufferParams =
928 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
929 DE_NULL, // const void* pNext;
930 0u, // VkBufferCreateFlags flags;
931 (VkDeviceSize)(sizeof(Vertex4RGBA) * m_vertices.size()), // VkDeviceSize size;
932 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage;
933 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
934 1u, // deUint32 queueFamilyCount;
935 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
938 m_vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
939 m_vertexBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_vertexBuffer), MemoryRequirement::HostVisible);
941 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_vertexBuffer, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset()));
943 // Load vertices into vertex buffer
944 deMemcpy(m_vertexBufferAlloc->getHostPtr(), m_vertices.data(), m_vertices.size() * sizeof(Vertex4RGBA));
945 flushMappedMemoryRange(vk, vkDevice, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset(), vertexBufferParams.size);
948 // Create command pool
950 const VkCommandPoolCreateInfo cmdPoolParams =
952 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
953 DE_NULL, // const void* pNext;
954 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCmdPoolCreateFlags flags;
955 queueFamilyIndex // deUint32 queueFamilyIndex;
957 m_cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
960 // Create command buffer
962 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
964 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
965 DE_NULL, // const void* pNext;
966 *m_cmdPool, // VkCommandPool commandPool;
967 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
968 1u // deUint32 bufferCount;
971 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
973 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
974 DE_NULL, // const void* pNext;
975 0u, // VkCommandBufferUsageFlags flags;
976 (const VkCommandBufferInheritanceInfo*)DE_NULL,
979 const VkClearValue attachmentClearValues[] =
981 defaultClearValue(m_colorFormat)
984 const VkRenderPassBeginInfo renderPassBeginInfo =
986 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
987 DE_NULL, // const void* pNext;
988 *m_renderPass, // VkRenderPass renderPass;
989 *m_framebuffer, // VkFramebuffer framebuffer;
990 { { 0, 0 } , { m_renderSize.x(), m_renderSize.y() } }, // VkRect2D renderArea;
991 1, // deUint32 clearValueCount;
992 attachmentClearValues // const VkClearValue* pClearValues;
995 const VkImageMemoryBarrier attachmentLayoutBarrier =
997 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
998 DE_NULL, // const void* pNext;
999 0u, // VkAccessFlags srcAccessMask;
1000 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask;
1001 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
1002 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
1003 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1004 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1005 *m_colorImage, // VkImage image;
1006 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
1009 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
1011 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1013 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0,
1014 0u, DE_NULL, 0u, DE_NULL, 1u, &attachmentLayoutBarrier);
1016 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
1018 // update push constant
1019 std::vector<tcu::Vec4> color(8, tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
1020 std::vector<tcu::Vec4> allOnes(8, tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
1022 const deUint32 kind = 2u;
1023 const void* value = DE_NULL;
1024 for (size_t rangeNdx = 0; rangeNdx < m_rangeCount; rangeNdx++)
1026 value = (m_pushConstantRange[rangeNdx].range.size == 4u) ? (void*)(&kind) : (void*)(&color[0]);
1028 vk.cmdPushConstants(*m_cmdBuffer, *m_pipelineLayout, m_pushConstantRange[rangeNdx].range.shaderStage, m_pushConstantRange[rangeNdx].range.offset, m_pushConstantRange[rangeNdx].range.size, value);
1030 if (m_pushConstantRange[rangeNdx].update.size < m_pushConstantRange[rangeNdx].range.size)
1032 value = (void*)(&allOnes[0]);
1033 vk.cmdPushConstants(*m_cmdBuffer, *m_pipelineLayout, m_pushConstantRange[rangeNdx].range.shaderStage, m_pushConstantRange[rangeNdx].update.offset, m_pushConstantRange[rangeNdx].update.size, value);
1038 const VkDeviceSize triangleOffset = (m_vertices.size() / TRIANGLE_COUNT) * sizeof(Vertex4RGBA);
1039 for (int triangleNdx = 0; triangleNdx < TRIANGLE_COUNT; triangleNdx++)
1041 VkDeviceSize vertexBufferOffset = triangleOffset * triangleNdx;
1043 if (m_multipleUpdate)
1045 vk.cmdPushConstants(*m_cmdBuffer, *m_pipelineLayout, m_pushConstantRange[0].range.shaderStage, m_pushConstantRange[0].range.offset, m_pushConstantRange[0].range.size, &triangleNdx);
1048 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_graphicsPipelines);
1049 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &m_vertexBuffer.get(), &vertexBufferOffset);
1050 vk.cmdBindDescriptorSets(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0, 1, &(*m_descriptorSet), 0, DE_NULL);
1052 vk.cmdDraw(*m_cmdBuffer, (deUint32)(m_vertices.size() / TRIANGLE_COUNT), 1, 0, 0);
1055 vk.cmdEndRenderPass(*m_cmdBuffer);
1056 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1061 const VkFenceCreateInfo fenceParams =
1063 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
1064 DE_NULL, // const void* pNext;
1065 0u // VkFenceCreateFlags flags;
1068 m_fence = createFence(vk, vkDevice, &fenceParams);
1072 PushConstantGraphicsTestInstance::~PushConstantGraphicsTestInstance (void)
1076 tcu::TestStatus PushConstantGraphicsTestInstance::iterate (void)
1078 const DeviceInterface& vk = m_context.getDeviceInterface();
1079 const VkDevice vkDevice = m_context.getDevice();
1080 const VkQueue queue = m_context.getUniversalQueue();
1081 const VkSubmitInfo submitInfo =
1083 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
1084 DE_NULL, // const void* pNext;
1085 0u, // deUint32 waitSemaphoreCount;
1086 DE_NULL, // const VkSemaphore* pWaitSemaphores;
1087 (const VkPipelineStageFlags*)DE_NULL,
1088 1u, // deUint32 commandBufferCount;
1089 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
1090 0u, // deUint32 signalSemaphoreCount;
1091 DE_NULL // const VkSemaphore* pSignalSemaphores;
1094 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1095 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1096 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity*/));
1098 return verifyImage();
1101 tcu::TestStatus PushConstantGraphicsTestInstance::verifyImage (void)
1103 const tcu::TextureFormat tcuColorFormat = mapVkFormat(m_colorFormat);
1104 const tcu::TextureFormat tcuDepthFormat = tcu::TextureFormat();
1105 const ColorVertexShader vertexShader;
1106 const ColorFragmentShader fragmentShader (tcuColorFormat, tcuDepthFormat);
1107 const rr::Program program (&vertexShader, &fragmentShader);
1108 ReferenceRenderer refRenderer (m_renderSize.x(), m_renderSize.y(), 1, tcuColorFormat, tcuDepthFormat, &program);
1109 bool compareOk = false;
1111 // Render reference image
1113 if (m_shaderFlags & VK_SHADER_STAGE_GEOMETRY_BIT)
1115 m_vertices = createQuad(0.5f);
1118 for (size_t rangeNdx = 0; rangeNdx < m_rangeCount; rangeNdx++)
1120 if (m_pushConstantRange[rangeNdx].update.size < m_pushConstantRange[rangeNdx].range.size)
1122 for (size_t vertexNdx = 0; vertexNdx < m_vertices.size(); vertexNdx++)
1124 m_vertices[vertexNdx].color.xyzw() = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
1129 if (m_multipleUpdate)
1131 for (size_t vertexNdx = 0; vertexNdx < 3; vertexNdx++)
1133 m_vertices[vertexNdx].color.xyz() = tcu::Vec3(0.0f, 1.0f, 0.0f);
1135 for (size_t vertexNdx = 3; vertexNdx < m_vertices.size(); vertexNdx++)
1137 m_vertices[vertexNdx].color.xyz() = tcu::Vec3(0.0f, 0.0f, 1.0f);
1141 for (int triangleNdx = 0; triangleNdx < TRIANGLE_COUNT; triangleNdx++)
1143 rr::RenderState renderState(refRenderer.getViewportState());
1145 refRenderer.draw(renderState,
1146 rr::PRIMITIVETYPE_TRIANGLES,
1147 std::vector<Vertex4RGBA>(m_vertices.begin() + triangleNdx * 3,
1148 m_vertices.begin() + (triangleNdx + 1) * 3));
1152 // Compare result with reference image
1154 const DeviceInterface& vk = m_context.getDeviceInterface();
1155 const VkDevice vkDevice = m_context.getDevice();
1156 const VkQueue queue = m_context.getUniversalQueue();
1157 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
1158 SimpleAllocator allocator (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
1159 de::MovePtr<tcu::TextureLevel> result = readColorAttachment(vk, vkDevice, queue, queueFamilyIndex, allocator, *m_colorImage, m_colorFormat, m_renderSize);
1161 compareOk = tcu::intThresholdPositionDeviationCompare(m_context.getTestContext().getLog(),
1164 refRenderer.getAccess(),
1165 result->getAccess(),
1166 tcu::UVec4(2, 2, 2, 2),
1167 tcu::IVec3(1, 1, 0),
1169 tcu::COMPARE_LOG_RESULT);
1173 return tcu::TestStatus::pass("Result image matches reference");
1175 return tcu::TestStatus::fail("Image mismatch");
1178 class PushConstantComputeTest : public vkt::TestCase
1181 PushConstantComputeTest (tcu::TestContext& testContext,
1182 const std::string& name,
1183 const std::string& description,
1184 const PushConstantData pushConstantRange);
1185 virtual ~PushConstantComputeTest (void);
1186 virtual void initPrograms (SourceCollections& sourceCollections) const;
1187 virtual TestInstance* createInstance (Context& context) const;
1190 const PushConstantData m_pushConstantRange;
1193 class PushConstantComputeTestInstance : public vkt::TestInstance
1196 PushConstantComputeTestInstance (Context& context,
1197 const PushConstantData pushConstantRange);
1198 virtual ~PushConstantComputeTestInstance (void);
1199 virtual tcu::TestStatus iterate (void);
1202 const PushConstantData m_pushConstantRange;
1204 Move<VkBuffer> m_outBuffer;
1205 de::MovePtr<Allocation> m_outBufferAlloc;
1206 Move<VkDescriptorPool> m_descriptorPool;
1207 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
1208 Move<VkDescriptorSet> m_descriptorSet;
1210 Move<VkPipelineLayout> m_pipelineLayout;
1211 Move<VkPipeline> m_computePipelines;
1213 Move<VkShaderModule> m_computeShaderModule;
1215 Move<VkCommandPool> m_cmdPool;
1216 Move<VkCommandBuffer> m_cmdBuffer;
1218 Move<VkFence> m_fence;
1221 PushConstantComputeTest::PushConstantComputeTest (tcu::TestContext& testContext,
1222 const std::string& name,
1223 const std::string& description,
1224 const PushConstantData pushConstantRange)
1225 : vkt::TestCase (testContext, name, description)
1226 , m_pushConstantRange (pushConstantRange)
1230 PushConstantComputeTest::~PushConstantComputeTest (void)
1234 TestInstance* PushConstantComputeTest::createInstance (Context& context) const
1236 return new PushConstantComputeTestInstance(context, m_pushConstantRange);
1239 void PushConstantComputeTest::initPrograms (SourceCollections& sourceCollections) const
1241 std::ostringstream computeSrc;
1243 computeSrc << "#version 450\n"
1244 << "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
1245 << "layout(std140, set = 0, binding = 0) writeonly buffer Output {\n"
1246 << " vec4 elements[];\n"
1248 << "layout(push_constant) uniform Material{\n"
1249 << " vec4 element;\n"
1251 << "void main (void)\n"
1253 << " outData.elements[gl_GlobalInvocationID.x] = matInst.element;\n"
1256 sourceCollections.glslSources.add("compute") << glu::ComputeSource(computeSrc.str());
1259 PushConstantComputeTestInstance::PushConstantComputeTestInstance (Context& context,
1260 const PushConstantData pushConstantRange)
1261 : vkt::TestInstance (context)
1262 , m_pushConstantRange (pushConstantRange)
1264 const DeviceInterface& vk = context.getDeviceInterface();
1265 const VkDevice vkDevice = context.getDevice();
1266 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1267 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
1269 // Create pipeline layout
1271 // create push constant range
1272 VkPushConstantRange pushConstantRanges;
1273 pushConstantRanges.stageFlags = m_pushConstantRange.range.shaderStage;
1274 pushConstantRanges.offset = m_pushConstantRange.range.offset;
1275 pushConstantRanges.size = m_pushConstantRange.range.size;
1277 // create descriptor set layout
1278 m_descriptorSetLayout = DescriptorSetLayoutBuilder().addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT).build(vk, vkDevice);
1280 // create descriptor pool
1281 m_descriptorPool = DescriptorPoolBuilder().addType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1u).build(vk, vkDevice, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
1283 // create uniform buffer
1284 const VkDeviceSize bufferSize = sizeof(tcu::Vec4) * 8;
1285 const VkBufferCreateInfo bufferCreateInfo =
1287 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1288 DE_NULL, // const void* pNext;
1289 0u, // VkBufferCreateFlags flags
1290 bufferSize, // VkDeviceSize size;
1291 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, // VkBufferUsageFlags usage;
1292 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1293 1u, // deUint32 queueFamilyCount;
1294 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
1297 m_outBuffer = createBuffer(vk, vkDevice, &bufferCreateInfo);
1298 m_outBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_outBuffer), MemoryRequirement::HostVisible);
1299 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_outBuffer, m_outBufferAlloc->getMemory(), m_outBufferAlloc->getOffset()));
1301 // create and update descriptor set
1302 const VkDescriptorSetAllocateInfo allocInfo =
1304 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
1305 DE_NULL, // const void* pNext;
1306 *m_descriptorPool, // VkDescriptorPool descriptorPool;
1307 1u, // uint32_t setLayoutCount;
1308 &(*m_descriptorSetLayout), // const VkDescriptorSetLayout* pSetLayouts;
1310 m_descriptorSet = allocateDescriptorSet(vk, vkDevice, &allocInfo);
1312 const VkDescriptorBufferInfo descriptorInfo = makeDescriptorBufferInfo(*m_outBuffer, (VkDeviceSize)0u, bufferSize);
1314 DescriptorSetUpdateBuilder()
1315 .writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &descriptorInfo)
1316 .update(vk, vkDevice);
1318 // create pipeline layout
1319 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
1321 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
1322 DE_NULL, // const void* pNext;
1323 0u, // VkPipelineLayoutCreateFlags flags;
1324 1u, // deUint32 descriptorSetCount;
1325 &(*m_descriptorSetLayout), // const VkDescriptorSetLayout* pSetLayouts;
1326 1u, // deUint32 pushConstantRangeCount;
1327 &pushConstantRanges // const VkPushConstantRange* pPushConstantRanges;
1330 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
1335 m_computeShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("compute"), 0);
1337 const VkPipelineShaderStageCreateInfo stageCreateInfo =
1339 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
1340 DE_NULL, // const void* pNext;
1341 0u, // VkPipelineShaderStageCreateFlags flags;
1342 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
1343 *m_computeShaderModule, // VkShaderModule module;
1344 "main", // const char* pName;
1345 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
1348 const VkComputePipelineCreateInfo createInfo =
1350 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
1351 DE_NULL, // const void* pNext;
1352 0u, // VkPipelineCreateFlags flags;
1353 stageCreateInfo, // VkPipelineShaderStageCreateInfo stage;
1354 *m_pipelineLayout, // VkPipelineLayout layout;
1355 (VkPipeline)0, // VkPipeline basePipelineHandle;
1356 0u, // int32_t basePipelineIndex;
1359 m_computePipelines = createComputePipeline(vk, vkDevice, (vk::VkPipelineCache)0u, &createInfo);
1362 // Create command pool
1364 const VkCommandPoolCreateInfo cmdPoolParams =
1366 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
1367 DE_NULL, // const void* pNext;
1368 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCmdPoolCreateFlags flags;
1369 queueFamilyIndex // deUint32 queueFamilyIndex;
1371 m_cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
1374 // Create command buffer
1376 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
1378 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
1379 DE_NULL, // const void* pNext;
1380 *m_cmdPool, // VkCommandPool commandPool;
1381 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
1382 1u // deUint32 bufferCount;
1385 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
1387 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1389 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1390 DE_NULL, // const void* pNext;
1391 0u, // VkCommandBufferUsageFlags flags;
1392 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1395 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1397 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *m_computePipelines);
1398 vk.cmdBindDescriptorSets(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *m_pipelineLayout, 0, 1, &(*m_descriptorSet), 0, DE_NULL);
1400 // update push constant
1401 tcu::Vec4 value = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
1402 vk.cmdPushConstants(*m_cmdBuffer, *m_pipelineLayout, m_pushConstantRange.range.shaderStage, m_pushConstantRange.range.offset, m_pushConstantRange.range.size, &value);
1404 vk.cmdDispatch(*m_cmdBuffer, 8, 1, 1);
1406 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1411 const VkFenceCreateInfo fenceParams =
1413 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
1414 DE_NULL, // const void* pNext;
1415 0u // VkFenceCreateFlags flags;
1418 m_fence = createFence(vk, vkDevice, &fenceParams);
1422 PushConstantComputeTestInstance::~PushConstantComputeTestInstance (void)
1426 tcu::TestStatus PushConstantComputeTestInstance::iterate (void)
1428 const DeviceInterface& vk = m_context.getDeviceInterface();
1429 const VkDevice vkDevice = m_context.getDevice();
1430 const VkQueue queue = m_context.getUniversalQueue();
1431 const VkSubmitInfo submitInfo =
1433 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
1434 DE_NULL, // const void* pNext;
1435 0u, // deUint32 waitSemaphoreCount;
1436 DE_NULL, // const VkSemaphore* pWaitSemaphores;
1437 (const VkPipelineStageFlags*)DE_NULL,
1438 1u, // deUint32 commandBufferCount;
1439 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
1440 0u, // deUint32 signalSemaphoreCount;
1441 DE_NULL // const VkSemaphore* pSignalSemaphores;
1444 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1445 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1446 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity*/));
1449 std::vector<tcu::Vec4> expectValue(8, tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
1450 if (deMemCmp((void*)(&expectValue[0]), m_outBufferAlloc->getHostPtr(), (size_t)(sizeof(tcu::Vec4) * 8)))
1452 return tcu::TestStatus::fail("Image mismatch");
1454 return tcu::TestStatus::pass("result image matches with reference");
1459 tcu::TestCaseGroup* createPushConstantTests (tcu::TestContext& testCtx)
1464 const char* description;
1466 PushConstantData range[MAX_RANGE_COUNT];
1467 deBool hasMultipleUpdates;
1468 } graphicsParams[] =
1470 // test range size from minimum valid size to maximum
1473 "test range size is 4 bytes(minimum valid size)",
1475 { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } , { 0, 4 } } },
1480 "test range size is 16 bytes, and together with a normal uniform",
1482 { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, { 0, 16 } } },
1487 "test range size is 128 bytes(maximum valid size)",
1489 { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 128 }, { 0, 128 } } },
1492 // test range count, including all valid shader stage in graphics pipeline, and also multiple shader stages share one single range
1494 "count_2_shader_VF",
1495 "test range count is 2, use vertex and fragment shaders",
1498 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, { 0, 16 } },
1499 { { VK_SHADER_STAGE_FRAGMENT_BIT, 16, 4 }, { 16, 4 } },
1504 "count_3shader_VGF",
1505 "test range count is 3, use vertex, geometry and fragment shaders",
1508 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, { 0, 16 } },
1509 { { VK_SHADER_STAGE_FRAGMENT_BIT, 16, 4 }, { 16, 4 } },
1510 { { VK_SHADER_STAGE_GEOMETRY_BIT, 20, 4 }, { 20, 4 } },
1515 "count_5_shader_VTGF",
1516 "test range count is 5, use vertex, tessellation, geometry and fragment shaders",
1519 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, { 0, 16 } },
1520 { { VK_SHADER_STAGE_FRAGMENT_BIT, 16, 4 }, { 16, 4 } },
1521 { { VK_SHADER_STAGE_GEOMETRY_BIT, 20, 4 }, { 20, 4 } },
1522 { { VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 24, 4 }, { 24, 4 } },
1523 { { VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, 32, 16 }, { 32, 16 } },
1528 "count_1_shader_VF",
1529 "test range count is 1, vertex and fragment shaders share one range",
1531 { { { VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4 }, { 0, 4 } } },
1534 // test data partial update and multiple times update
1536 "data_update_partial_1",
1537 "test partial update of the values",
1539 { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 32 }, { 4, 24 } } },
1543 "data_update_partial_2",
1544 "test partial update of the values",
1546 { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 48 }, { 32, 16 } } },
1550 "data_update_multiple",
1551 "test multiple times update of the values",
1553 { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, { 0, 4 } } },
1561 const char* description;
1562 PushConstantData range;
1567 "test compute pipeline",
1568 { { VK_SHADER_STAGE_COMPUTE_BIT, 0, 16 }, { 0, 16 } },
1572 de::MovePtr<tcu::TestCaseGroup> pushConstantTests (new tcu::TestCaseGroup(testCtx, "push_constant", "PushConstant tests"));
1574 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics_pipeline", "graphics pipeline"));
1575 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(graphicsParams); ndx++)
1577 graphicsTests->addChild(new PushConstantGraphicsTest(testCtx, graphicsParams[ndx].name, graphicsParams[ndx].description, graphicsParams[ndx].count, graphicsParams[ndx].range, graphicsParams[ndx].hasMultipleUpdates));
1579 pushConstantTests->addChild(graphicsTests.release());
1581 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute_pipeline", "compute pipeline"));
1582 computeTests->addChild(new PushConstantComputeTest(testCtx, computeParams[0].name, computeParams[0].description, computeParams[0].range));
1583 pushConstantTests->addChild(computeTests.release());
1585 return pushConstantTests.release();