1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 Google Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Simple Smoke Tests
22 *//*--------------------------------------------------------------------*/
24 #include "vktApiTests.hpp"
26 #include "vktTestCaseUtil.hpp"
29 #include "vkPlatform.hpp"
30 #include "vkStrUtil.hpp"
32 #include "vkRefUtil.hpp"
33 #include "vkQueryUtil.hpp"
34 #include "vkMemUtil.hpp"
35 #include "vkDeviceUtil.hpp"
36 #include "vkPrograms.hpp"
37 #include "vkTypeUtil.hpp"
38 #include "vkImageUtil.hpp"
40 #include "tcuTestLog.hpp"
41 #include "tcuFormatUtil.hpp"
42 #include "tcuTextureUtil.hpp"
43 #include "tcuImageCompare.hpp"
45 #include "rrRenderer.hpp"
47 #include "deUniquePtr.hpp"
62 tcu::TestStatus createSamplerTest (Context& context)
64 const VkDevice vkDevice = context.getDevice();
65 const DeviceInterface& vk = context.getDeviceInterface();
68 const struct VkSamplerCreateInfo samplerInfo =
70 VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, // sType
73 VK_FILTER_NEAREST, // magFilter
74 VK_FILTER_NEAREST, // minFilter
75 VK_SAMPLER_MIPMAP_MODE_NEAREST, // mipmapMode
76 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // addressModeU
77 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // addressModeV
78 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // addressModeW
80 VK_FALSE, // anisotropyEnable
81 1.0f, // maxAnisotropy
82 DE_FALSE, // compareEnable
83 VK_COMPARE_OP_ALWAYS, // compareOp
86 VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK, // borderColor
87 VK_FALSE, // unnormalizedCoords
90 Move<VkSampler> tmpSampler = createSampler(vk, vkDevice, &samplerInfo);
91 Move<VkSampler> tmp2Sampler;
93 tmp2Sampler = tmpSampler;
95 const Unique<VkSampler> sampler (tmp2Sampler);
98 return tcu::TestStatus::pass("Creating sampler succeeded");
101 void createShaderProgs (SourceCollections& dst)
103 dst.glslSources.add("test") << glu::VertexSource(
105 "in highp vec4 a_position;\n"
106 "void main (void) { gl_Position = a_position; }\n");
109 tcu::TestStatus createShaderModuleTest (Context& context)
111 const VkDevice vkDevice = context.getDevice();
112 const DeviceInterface& vk = context.getDeviceInterface();
113 const Unique<VkShaderModule> shader (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("test"), 0));
115 return tcu::TestStatus::pass("Creating shader module succeeded");
118 void createTriangleAsmProgs (SourceCollections& dst)
120 dst.spirvAsmSources.add("vert") <<
121 " OpCapability Shader\n"
122 "%1 = OpExtInstImport \"GLSL.std.450\"\n"
123 " OpMemoryModel Logical GLSL450\n"
124 " OpEntryPoint Vertex %4 \"main\" %10 %12 %16 %17\n"
125 " OpSource ESSL 300\n"
126 " OpName %4 \"main\"\n"
127 " OpName %10 \"gl_Position\"\n"
128 " OpName %12 \"a_position\"\n"
129 " OpName %16 \"gl_VertexIndex\"\n"
130 " OpName %17 \"gl_InstanceIndex\"\n"
131 " OpDecorate %10 BuiltIn Position\n"
132 " OpDecorate %12 Location 0\n"
133 " OpDecorate %16 BuiltIn VertexIndex\n"
134 " OpDecorate %17 BuiltIn InstanceIndex\n"
136 "%3 = OpTypeFunction %2\n"
137 "%7 = OpTypeFloat 32\n"
138 "%8 = OpTypeVector %7 4\n"
139 "%9 = OpTypePointer Output %8\n"
140 "%10 = OpVariable %9 Output\n"
141 "%11 = OpTypePointer Input %8\n"
142 "%12 = OpVariable %11 Input\n"
143 "%14 = OpTypeInt 32 1\n"
144 "%15 = OpTypePointer Input %14\n"
145 "%16 = OpVariable %15 Input\n"
146 "%17 = OpVariable %15 Input\n"
147 "%4 = OpFunction %2 None %3\n"
149 "%13 = OpLoad %8 %12\n"
155 dst.spirvAsmSources.add("frag") <<
156 " OpCapability Shader\n"
157 "%1 = OpExtInstImport \"GLSL.std.450\"\n"
158 " OpMemoryModel Logical GLSL450\n"
159 " OpEntryPoint Fragment %4 \"main\" %10\n"
160 " OpExecutionMode %4 OriginLowerLeft\n"
161 " OpSource ESSL 300\n"
162 " OpName %4 \"main\"\n"
163 " OpName %10 \"o_color\"\n"
164 " OpDecorate %10 RelaxedPrecision\n"
165 " OpDecorate %10 Location 0\n"
167 "%3 = OpTypeFunction %2\n"
168 "%7 = OpTypeFloat 32\n"
169 "%8 = OpTypeVector %7 4\n"
170 "%9 = OpTypePointer Output %8\n"
171 "%10 = OpVariable %9 Output\n"
172 "%11 = OpConstant %7 1065353216\n"
173 "%12 = OpConstant %7 0\n"
174 "%13 = OpConstantComposite %8 %11 %12 %11 %11\n"
175 "%4 = OpFunction %2 None %3\n"
184 void createTriangleProgs (SourceCollections& dst)
186 dst.glslSources.add("vert") << glu::VertexSource(
188 "layout(location = 0) in highp vec4 a_position;\n"
189 "void main (void) { gl_Position = a_position; }\n");
190 dst.glslSources.add("frag") << glu::FragmentSource(
192 "layout(location = 0) out lowp vec4 o_color;\n"
193 "void main (void) { o_color = vec4(1.0, 0.0, 1.0, 1.0); }\n");
196 void createProgsNoOpName (SourceCollections& dst)
198 dst.spirvAsmSources.add("vert") <<
199 "OpCapability Shader\n"
200 "%1 = OpExtInstImport \"GLSL.std.450\"\n"
201 "OpMemoryModel Logical GLSL450\n"
202 "OpEntryPoint Vertex %4 \"main\" %20 %22 %26\n"
203 "OpSource ESSL 310\n"
204 "OpMemberDecorate %18 0 BuiltIn Position\n"
205 "OpMemberDecorate %18 1 BuiltIn PointSize\n"
206 "OpDecorate %18 Block\n"
207 "OpDecorate %22 Location 0\n"
208 "OpDecorate %26 Location 2\n"
210 "%3 = OpTypeFunction %2\n"
211 "%6 = OpTypeFloat 32\n"
212 "%7 = OpTypeVector %6 4\n"
213 "%8 = OpTypeStruct %7\n"
214 "%9 = OpTypePointer Function %8\n"
215 "%11 = OpTypeInt 32 1\n"
216 "%12 = OpConstant %11 0\n"
217 "%13 = OpConstant %6 1\n"
218 "%14 = OpConstant %6 0\n"
219 "%15 = OpConstantComposite %7 %13 %14 %13 %13\n"
220 "%16 = OpTypePointer Function %7\n"
221 "%18 = OpTypeStruct %7 %6\n"
222 "%19 = OpTypePointer Output %18\n"
223 "%20 = OpVariable %19 Output\n"
224 "%21 = OpTypePointer Input %7\n"
225 "%22 = OpVariable %21 Input\n"
226 "%24 = OpTypePointer Output %7\n"
227 "%26 = OpVariable %24 Output\n"
228 "%4 = OpFunction %2 None %3\n"
230 "%10 = OpVariable %9 Function\n"
231 "%17 = OpAccessChain %16 %10 %12\n"
233 "%23 = OpLoad %7 %22\n"
234 "%25 = OpAccessChain %24 %20 %12\n"
236 "%27 = OpAccessChain %16 %10 %12\n"
237 "%28 = OpLoad %7 %27\n"
241 dst.spirvAsmSources.add("frag") <<
242 "OpCapability Shader\n"
243 "%1 = OpExtInstImport \"GLSL.std.450\"\n"
244 "OpMemoryModel Logical GLSL450\n"
245 "OpEntryPoint Fragment %4 \"main\" %9 %11\n"
246 "OpExecutionMode %4 OriginUpperLeft\n"
247 "OpSource ESSL 310\n"
248 "OpDecorate %9 RelaxedPrecision\n"
249 "OpDecorate %9 Location 0\n"
250 "OpDecorate %11 Location 2\n"
252 "%3 = OpTypeFunction %2\n"
253 "%6 = OpTypeFloat 32\n"
254 "%7 = OpTypeVector %6 4\n"
255 "%8 = OpTypePointer Output %7\n"
256 "%9 = OpVariable %8 Output\n"
257 "%10 = OpTypePointer Input %7\n"
258 "%11 = OpVariable %10 Input\n"
259 "%4 = OpFunction %2 None %3\n"
261 "%12 = OpLoad %7 %11\n"
267 class RefVertexShader : public rr::VertexShader
270 RefVertexShader (void)
271 : rr::VertexShader(1, 0)
273 m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
276 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
278 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
280 packets[packetNdx]->position = rr::readVertexAttribFloat(inputs[0],
281 packets[packetNdx]->instanceNdx,
282 packets[packetNdx]->vertexNdx);
287 class RefFragmentShader : public rr::FragmentShader
290 RefFragmentShader (void)
291 : rr::FragmentShader(0, 1)
293 m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
296 void shadeFragments (rr::FragmentPacket*, const int numPackets, const rr::FragmentShadingContext& context) const
298 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
300 for (int fragNdx = 0; fragNdx < rr::NUM_FRAGMENTS_PER_PACKET; ++fragNdx)
302 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f));
308 void renderReferenceTriangle (const tcu::PixelBufferAccess& dst, const tcu::Vec4 (&vertices)[3])
310 const RefVertexShader vertShader;
311 const RefFragmentShader fragShader;
312 const rr::Program program (&vertShader, &fragShader);
313 const rr::MultisamplePixelBufferAccess colorBuffer = rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(dst);
314 const rr::RenderTarget renderTarget (colorBuffer);
315 const rr::RenderState renderState ((rr::ViewportState(colorBuffer)), rr::VIEWPORTORIENTATION_UPPER_LEFT);
316 const rr::Renderer renderer;
317 const rr::VertexAttrib vertexAttribs[] =
319 rr::VertexAttrib(rr::VERTEXATTRIBTYPE_FLOAT, 4, sizeof(tcu::Vec4), 0, vertices[0].getPtr())
322 renderer.draw(rr::DrawCommand(renderState,
325 DE_LENGTH_OF_ARRAY(vertexAttribs),
327 rr::PrimitiveList(rr::PRIMITIVETYPE_TRIANGLES, DE_LENGTH_OF_ARRAY(vertices), 0)));
330 tcu::TestStatus renderTriangleTest (Context& context)
332 const VkDevice vkDevice = context.getDevice();
333 const DeviceInterface& vk = context.getDeviceInterface();
334 const VkQueue queue = context.getUniversalQueue();
335 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
336 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
337 const tcu::IVec2 renderSize (256, 256);
338 const VkFormat colorFormat = VK_FORMAT_R8G8B8A8_UNORM;
339 const tcu::Vec4 clearColor (0.125f, 0.25f, 0.75f, 1.0f);
341 const tcu::Vec4 vertices[] =
343 tcu::Vec4(-0.5f, -0.5f, 0.0f, 1.0f),
344 tcu::Vec4(+0.5f, -0.5f, 0.0f, 1.0f),
345 tcu::Vec4( 0.0f, +0.5f, 0.0f, 1.0f)
348 const VkBufferCreateInfo vertexBufferParams =
350 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // sType
353 (VkDeviceSize)sizeof(vertices), // size
354 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // usage
355 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
356 1u, // queueFamilyIndexCount
357 &queueFamilyIndex, // pQueueFamilyIndices
359 const Unique<VkBuffer> vertexBuffer (createBuffer(vk, vkDevice, &vertexBufferParams));
360 const UniquePtr<Allocation> vertexBufferMemory (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible));
362 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferMemory->getMemory(), vertexBufferMemory->getOffset()));
364 const VkDeviceSize imageSizeBytes = (VkDeviceSize)(sizeof(deUint32)*renderSize.x()*renderSize.y());
365 const VkBufferCreateInfo readImageBufferParams =
367 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // sType
369 (VkBufferCreateFlags)0u, // flags
370 imageSizeBytes, // size
371 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // usage
372 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
373 1u, // queueFamilyIndexCount
374 &queueFamilyIndex, // pQueueFamilyIndices
376 const Unique<VkBuffer> readImageBuffer (createBuffer(vk, vkDevice, &readImageBufferParams));
377 const UniquePtr<Allocation> readImageBufferMemory (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *readImageBuffer), MemoryRequirement::HostVisible));
379 VK_CHECK(vk.bindBufferMemory(vkDevice, *readImageBuffer, readImageBufferMemory->getMemory(), readImageBufferMemory->getOffset()));
381 const VkImageCreateInfo imageParams =
383 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // sType
386 VK_IMAGE_TYPE_2D, // imageType
387 VK_FORMAT_R8G8B8A8_UNORM, // format
388 { (deUint32)renderSize.x(), (deUint32)renderSize.y(), 1 }, // extent
391 VK_SAMPLE_COUNT_1_BIT, // samples
392 VK_IMAGE_TILING_OPTIMAL, // tiling
393 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // usage
394 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
395 1u, // queueFamilyIndexCount
396 &queueFamilyIndex, // pQueueFamilyIndices
397 VK_IMAGE_LAYOUT_UNDEFINED, // initialLayout
400 const Unique<VkImage> image (createImage(vk, vkDevice, &imageParams));
401 const UniquePtr<Allocation> imageMemory (memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any));
403 VK_CHECK(vk.bindImageMemory(vkDevice, *image, imageMemory->getMemory(), imageMemory->getOffset()));
405 const VkAttachmentDescription colorAttDesc =
408 VK_FORMAT_R8G8B8A8_UNORM, // format
409 VK_SAMPLE_COUNT_1_BIT, // samples
410 VK_ATTACHMENT_LOAD_OP_CLEAR, // loadOp
411 VK_ATTACHMENT_STORE_OP_STORE, // storeOp
412 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // stencilLoadOp
413 VK_ATTACHMENT_STORE_OP_DONT_CARE, // stencilStoreOp
414 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // initialLayout
415 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // finalLayout
417 const VkAttachmentReference colorAttRef =
420 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // layout
422 const VkSubpassDescription subpassDesc =
424 (VkSubpassDescriptionFlags)0u, // flags
425 VK_PIPELINE_BIND_POINT_GRAPHICS, // pipelineBindPoint
426 0u, // inputAttachmentCount
427 DE_NULL, // pInputAttachments
428 1u, // colorAttachmentCount
429 &colorAttRef, // pColorAttachments
430 DE_NULL, // pResolveAttachments
431 DE_NULL, // depthStencilAttachment
432 0u, // preserveAttachmentCount
433 DE_NULL, // pPreserveAttachments
435 const VkRenderPassCreateInfo renderPassParams =
437 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // sType
440 1u, // attachmentCount
441 &colorAttDesc, // pAttachments
443 &subpassDesc, // pSubpasses
444 0u, // dependencyCount
445 DE_NULL, // pDependencies
447 const Unique<VkRenderPass> renderPass (createRenderPass(vk, vkDevice, &renderPassParams));
449 const VkImageViewCreateInfo colorAttViewParams =
451 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // sType
455 VK_IMAGE_VIEW_TYPE_2D, // viewType
456 VK_FORMAT_R8G8B8A8_UNORM, // format
458 VK_COMPONENT_SWIZZLE_R,
459 VK_COMPONENT_SWIZZLE_G,
460 VK_COMPONENT_SWIZZLE_B,
461 VK_COMPONENT_SWIZZLE_A
464 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
467 0u, // baseArrayLayer
469 }, // subresourceRange
471 const Unique<VkImageView> colorAttView (createImageView(vk, vkDevice, &colorAttViewParams));
474 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
476 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType
478 (vk::VkPipelineLayoutCreateFlags)0,
479 0u, // setLayoutCount
480 DE_NULL, // pSetLayouts
481 0u, // pushConstantRangeCount
482 DE_NULL, // pPushConstantRanges
484 const Unique<VkPipelineLayout> pipelineLayout (createPipelineLayout(vk, vkDevice, &pipelineLayoutParams));
487 const Unique<VkShaderModule> vertShaderModule (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("vert"), 0));
488 const Unique<VkShaderModule> fragShaderModule (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("frag"), 0));
491 const VkSpecializationInfo emptyShaderSpecParams =
498 const VkPipelineShaderStageCreateInfo shaderStageParams[] =
501 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // sType
504 VK_SHADER_STAGE_VERTEX_BIT, // stage
505 *vertShaderModule, // module
507 &emptyShaderSpecParams, // pSpecializationInfo
510 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // sType
513 VK_SHADER_STAGE_FRAGMENT_BIT, // stage
514 *fragShaderModule, // module
516 &emptyShaderSpecParams, // pSpecializationInfo
519 const VkPipelineDepthStencilStateCreateInfo depthStencilParams =
521 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // sType
524 DE_FALSE, // depthTestEnable
525 DE_FALSE, // depthWriteEnable
526 VK_COMPARE_OP_ALWAYS, // depthCompareOp
527 DE_FALSE, // depthBoundsTestEnable
528 DE_FALSE, // stencilTestEnable
530 VK_STENCIL_OP_KEEP, // failOp
531 VK_STENCIL_OP_KEEP, // passOp
532 VK_STENCIL_OP_KEEP, // depthFailOp
533 VK_COMPARE_OP_ALWAYS, // compareOp
539 VK_STENCIL_OP_KEEP, // failOp
540 VK_STENCIL_OP_KEEP, // passOp
541 VK_STENCIL_OP_KEEP, // depthFailOp
542 VK_COMPARE_OP_ALWAYS, // compareOp
547 0.0f, // float minDepthBounds;
548 1.0f, // float maxDepthBounds;
550 const VkViewport viewport0 =
554 (float)renderSize.x(), // width
555 (float)renderSize.y(), // height
559 const VkRect2D scissor0 =
566 (deUint32)renderSize.x(), // width
567 (deUint32)renderSize.y(), // height
570 const VkPipelineViewportStateCreateInfo viewportParams =
572 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // sType
576 &viewport0, // pViewports
578 &scissor0 // pScissors
580 const VkSampleMask sampleMask = ~0u;
581 const VkPipelineMultisampleStateCreateInfo multisampleParams =
583 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // sType
586 VK_SAMPLE_COUNT_1_BIT, // rasterizationSamples
587 VK_FALSE, // sampleShadingEnable
588 0.0f, // minSampleShading
589 &sampleMask, // sampleMask
590 VK_FALSE, // alphaToCoverageEnable
591 VK_FALSE, // alphaToOneEnable
593 const VkPipelineRasterizationStateCreateInfo rasterParams =
595 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // sType
598 VK_TRUE, // depthClampEnable
599 VK_FALSE, // rasterizerDiscardEnable
600 VK_POLYGON_MODE_FILL, // polygonMode
601 VK_CULL_MODE_NONE, // cullMode
602 VK_FRONT_FACE_COUNTER_CLOCKWISE, // frontFace
603 VK_FALSE, // depthBiasEnable
604 0.0f, // depthBiasConstantFactor
605 0.0f, // depthBiasClamp
606 0.0f, // depthBiasSlopeFactor
609 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyParams =
611 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // sType
614 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // topology
615 DE_FALSE, // primitiveRestartEnable
617 const VkVertexInputBindingDescription vertexBinding0 =
620 (deUint32)sizeof(tcu::Vec4), // stride
621 VK_VERTEX_INPUT_RATE_VERTEX, // inputRate
623 const VkVertexInputAttributeDescription vertexAttrib0 =
627 VK_FORMAT_R32G32B32A32_SFLOAT, // format
630 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
632 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // sType
635 1u, // vertexBindingDescriptionCount
636 &vertexBinding0, // pVertexBindingDescriptions
637 1u, // vertexAttributeDescriptionCount
638 &vertexAttrib0, // pVertexAttributeDescriptions
640 const VkPipelineColorBlendAttachmentState attBlendParams =
642 VK_FALSE, // blendEnable
643 VK_BLEND_FACTOR_ONE, // srcColorBlendFactor
644 VK_BLEND_FACTOR_ZERO, // dstColorBlendFactor
645 VK_BLEND_OP_ADD, // colorBlendOp
646 VK_BLEND_FACTOR_ONE, // srcAlphaBlendFactor
647 VK_BLEND_FACTOR_ZERO, // dstAlphaBlendFactor
648 VK_BLEND_OP_ADD, // alphaBlendOp
649 (VK_COLOR_COMPONENT_R_BIT|
650 VK_COLOR_COMPONENT_G_BIT|
651 VK_COLOR_COMPONENT_B_BIT|
652 VK_COLOR_COMPONENT_A_BIT), // colorWriteMask
654 const VkPipelineColorBlendStateCreateInfo blendParams =
656 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // sType
659 DE_FALSE, // logicOpEnable
660 VK_LOGIC_OP_COPY, // logicOp
661 1u, // attachmentCount
662 &attBlendParams, // pAttachments
663 { 0.0f, 0.0f, 0.0f, 0.0f }, // blendConstants[4]
665 const VkGraphicsPipelineCreateInfo pipelineParams =
667 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // sType
670 (deUint32)DE_LENGTH_OF_ARRAY(shaderStageParams), // stageCount
671 shaderStageParams, // pStages
672 &vertexInputStateParams, // pVertexInputState
673 &inputAssemblyParams, // pInputAssemblyState
674 DE_NULL, // pTessellationState
675 &viewportParams, // pViewportState
676 &rasterParams, // pRasterizationState
677 &multisampleParams, // pMultisampleState
678 &depthStencilParams, // pDepthStencilState
679 &blendParams, // pColorBlendState
680 (const VkPipelineDynamicStateCreateInfo*)DE_NULL, // pDynamicState
681 *pipelineLayout, // layout
682 *renderPass, // renderPass
684 DE_NULL, // basePipelineHandle
685 0u, // basePipelineIndex
688 const Unique<VkPipeline> pipeline (createGraphicsPipeline(vk, vkDevice, DE_NULL, &pipelineParams));
691 const VkFramebufferCreateInfo framebufferParams =
693 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // sType
696 *renderPass, // renderPass
697 1u, // attachmentCount
698 &*colorAttView, // pAttachments
699 (deUint32)renderSize.x(), // width
700 (deUint32)renderSize.y(), // height
703 const Unique<VkFramebuffer> framebuffer (createFramebuffer(vk, vkDevice, &framebufferParams));
705 const VkCommandPoolCreateInfo cmdPoolParams =
707 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType
709 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags
710 queueFamilyIndex, // queueFamilyIndex
712 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
715 const VkCommandBufferAllocateInfo cmdBufParams =
717 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType
720 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level
723 const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
725 const VkCommandBufferBeginInfo cmdBufBeginParams =
727 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
730 (const VkCommandBufferInheritanceInfo*)DE_NULL,
734 VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginParams));
737 const VkMemoryBarrier vertFlushBarrier =
739 VK_STRUCTURE_TYPE_MEMORY_BARRIER, // sType
741 VK_ACCESS_HOST_WRITE_BIT, // srcAccessMask
742 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, // dstAccessMask
744 const VkImageMemoryBarrier colorAttBarrier =
746 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
749 (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT|
750 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT), // dstAccessMask
751 VK_IMAGE_LAYOUT_UNDEFINED, // oldLayout
752 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout
753 queueFamilyIndex, // srcQueueFamilyIndex
754 queueFamilyIndex, // dstQueueFamilyIndex
757 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
760 0u, // baseArrayLayer
762 } // subresourceRange
764 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, (VkDependencyFlags)0, 1, &vertFlushBarrier, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &colorAttBarrier);
768 const VkClearValue clearValue = makeClearValueColorF32(clearColor[0],
772 const VkRenderPassBeginInfo passBeginParams =
774 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // sType
776 *renderPass, // renderPass
777 *framebuffer, // framebuffer
780 { (deUint32)renderSize.x(), (deUint32)renderSize.y() }
782 1u, // clearValueCount
783 &clearValue, // pClearValues
785 vk.cmdBeginRenderPass(*cmdBuf, &passBeginParams, VK_SUBPASS_CONTENTS_INLINE);
788 vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
790 const VkDeviceSize bindingOffset = 0;
791 vk.cmdBindVertexBuffers(*cmdBuf, 0u, 1u, &vertexBuffer.get(), &bindingOffset);
793 vk.cmdDraw(*cmdBuf, 3u, 1u, 0u, 0u);
794 vk.cmdEndRenderPass(*cmdBuf);
797 const VkImageMemoryBarrier renderFinishBarrier =
799 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
801 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // outputMask
802 VK_ACCESS_TRANSFER_READ_BIT, // inputMask
803 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // oldLayout
804 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // newLayout
805 queueFamilyIndex, // srcQueueFamilyIndex
806 queueFamilyIndex, // dstQueueFamilyIndex
809 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
812 0u, // baseArraySlice
814 } // subresourceRange
816 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &renderFinishBarrier);
820 const VkBufferImageCopy copyParams =
822 (VkDeviceSize)0u, // bufferOffset
823 (deUint32)renderSize.x(), // bufferRowLength
824 (deUint32)renderSize.y(), // bufferImageHeight
826 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
828 0u, // baseArrayLayer
830 }, // imageSubresource
831 { 0u, 0u, 0u }, // imageOffset
833 (deUint32)renderSize.x(),
834 (deUint32)renderSize.y(),
838 vk.cmdCopyImageToBuffer(*cmdBuf, *image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *readImageBuffer, 1u, ©Params);
842 const VkBufferMemoryBarrier copyFinishBarrier =
844 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // sType
846 VK_ACCESS_TRANSFER_WRITE_BIT, // srcAccessMask
847 VK_ACCESS_HOST_READ_BIT, // dstAccessMask
848 queueFamilyIndex, // srcQueueFamilyIndex
849 queueFamilyIndex, // dstQueueFamilyIndex
850 *readImageBuffer, // buffer
852 imageSizeBytes // size
854 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, ©FinishBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
857 VK_CHECK(vk.endCommandBuffer(*cmdBuf));
859 // Upload vertex data
861 const VkMappedMemoryRange range =
863 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // sType
865 vertexBufferMemory->getMemory(), // memory
867 (VkDeviceSize)sizeof(vertices), // size
869 void* vertexBufPtr = vertexBufferMemory->getHostPtr();
871 deMemcpy(vertexBufPtr, &vertices[0], sizeof(vertices));
872 VK_CHECK(vk.flushMappedMemoryRanges(vkDevice, 1u, &range));
875 // Submit & wait for completion
877 const VkFenceCreateInfo fenceParams =
879 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // sType
883 const VkSubmitInfo submitInfo =
885 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
887 0u, // waitSemaphoreCount
888 DE_NULL, // pWaitSemaphores
889 (const VkPipelineStageFlags*)DE_NULL,
890 1u, // commandBufferCount
891 &cmdBuf.get(), // pCommandBuffers
892 0u, // signalSemaphoreCount
893 DE_NULL, // pSignalSemaphores
895 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceParams));
897 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
898 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), DE_TRUE, ~0ull));
901 // Read results, render reference, compare
903 const tcu::TextureFormat tcuFormat = vk::mapVkFormat(colorFormat);
904 const VkMappedMemoryRange range =
906 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // sType
908 readImageBufferMemory->getMemory(), // memory
910 imageSizeBytes, // size
912 const tcu::ConstPixelBufferAccess resultAccess (tcuFormat, renderSize.x(), renderSize.y(), 1, readImageBufferMemory->getHostPtr());
914 VK_CHECK(vk.invalidateMappedMemoryRanges(vkDevice, 1u, &range));
917 tcu::TextureLevel refImage (tcuFormat, renderSize.x(), renderSize.y());
918 const tcu::UVec4 threshold (0u);
919 const tcu::IVec3 posDeviation (1,1,0);
921 tcu::clear(refImage.getAccess(), clearColor);
922 renderReferenceTriangle(refImage.getAccess(), vertices);
924 if (tcu::intThresholdPositionDeviationCompare(context.getTestContext().getLog(),
926 "Image comparison result",
927 refImage.getAccess(),
932 tcu::COMPARE_LOG_RESULT))
933 return tcu::TestStatus::pass("Rendering succeeded");
935 return tcu::TestStatus::fail("Image comparison failed");
939 return tcu::TestStatus::pass("Rendering succeeded");
942 tcu::TestStatus renderTriangleUnusedResolveAttachmentTest (Context& context)
944 const VkDevice vkDevice = context.getDevice();
945 const DeviceInterface& vk = context.getDeviceInterface();
946 const VkQueue queue = context.getUniversalQueue();
947 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
948 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
949 const tcu::IVec2 renderSize (256, 256);
950 const VkFormat colorFormat = VK_FORMAT_R8G8B8A8_UNORM;
951 const tcu::Vec4 clearColor (0.125f, 0.25f, 0.75f, 1.0f);
953 const tcu::Vec4 vertices[] =
955 tcu::Vec4(-0.5f, -0.5f, 0.0f, 1.0f),
956 tcu::Vec4(+0.5f, -0.5f, 0.0f, 1.0f),
957 tcu::Vec4( 0.0f, +0.5f, 0.0f, 1.0f)
960 const VkBufferCreateInfo vertexBufferParams =
962 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // sType
965 (VkDeviceSize)sizeof(vertices), // size
966 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // usage
967 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
968 1u, // queueFamilyIndexCount
969 &queueFamilyIndex, // pQueueFamilyIndices
971 const Unique<VkBuffer> vertexBuffer (createBuffer(vk, vkDevice, &vertexBufferParams));
972 const UniquePtr<Allocation> vertexBufferMemory (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible));
974 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferMemory->getMemory(), vertexBufferMemory->getOffset()));
976 const VkDeviceSize imageSizeBytes = (VkDeviceSize)(sizeof(deUint32)*renderSize.x()*renderSize.y());
977 const VkBufferCreateInfo readImageBufferParams =
979 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // sType
981 (VkBufferCreateFlags)0u, // flags
982 imageSizeBytes, // size
983 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // usage
984 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
985 1u, // queueFamilyIndexCount
986 &queueFamilyIndex, // pQueueFamilyIndices
988 const Unique<VkBuffer> readImageBuffer (createBuffer(vk, vkDevice, &readImageBufferParams));
989 const UniquePtr<Allocation> readImageBufferMemory (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *readImageBuffer), MemoryRequirement::HostVisible));
991 VK_CHECK(vk.bindBufferMemory(vkDevice, *readImageBuffer, readImageBufferMemory->getMemory(), readImageBufferMemory->getOffset()));
993 const VkImageCreateInfo imageParams =
995 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // sType
998 VK_IMAGE_TYPE_2D, // imageType
999 VK_FORMAT_R8G8B8A8_UNORM, // format
1000 { (deUint32)renderSize.x(), (deUint32)renderSize.y(), 1 }, // extent
1003 VK_SAMPLE_COUNT_1_BIT, // samples
1004 VK_IMAGE_TILING_OPTIMAL, // tiling
1005 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // usage
1006 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
1007 1u, // queueFamilyIndexCount
1008 &queueFamilyIndex, // pQueueFamilyIndices
1009 VK_IMAGE_LAYOUT_UNDEFINED, // initialLayout
1012 const Unique<VkImage> image (createImage(vk, vkDevice, &imageParams));
1013 const UniquePtr<Allocation> imageMemory (memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any));
1015 VK_CHECK(vk.bindImageMemory(vkDevice, *image, imageMemory->getMemory(), imageMemory->getOffset()));
1017 const VkAttachmentDescription colorAttDesc =
1020 VK_FORMAT_R8G8B8A8_UNORM, // format
1021 VK_SAMPLE_COUNT_1_BIT, // samples
1022 VK_ATTACHMENT_LOAD_OP_CLEAR, // loadOp
1023 VK_ATTACHMENT_STORE_OP_STORE, // storeOp
1024 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // stencilLoadOp
1025 VK_ATTACHMENT_STORE_OP_DONT_CARE, // stencilStoreOp
1026 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // initialLayout
1027 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // finalLayout
1029 const VkAttachmentReference colorAttRef =
1032 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // layout
1034 const VkAttachmentReference resolveAttRef =
1036 VK_ATTACHMENT_UNUSED,
1037 VK_IMAGE_LAYOUT_GENERAL
1039 const VkSubpassDescription subpassDesc =
1041 (VkSubpassDescriptionFlags)0u, // flags
1042 VK_PIPELINE_BIND_POINT_GRAPHICS, // pipelineBindPoint
1043 0u, // inputAttachmentCount
1044 DE_NULL, // pInputAttachments
1045 1u, // colorAttachmentCount
1046 &colorAttRef, // pColorAttachments
1047 &resolveAttRef, // pResolveAttachments
1048 DE_NULL, // depthStencilAttachment
1049 0u, // preserveAttachmentCount
1050 DE_NULL, // pPreserveAttachments
1052 const VkRenderPassCreateInfo renderPassParams =
1054 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // sType
1057 1u, // attachmentCount
1058 &colorAttDesc, // pAttachments
1060 &subpassDesc, // pSubpasses
1061 0u, // dependencyCount
1062 DE_NULL, // pDependencies
1064 const Unique<VkRenderPass> renderPass (createRenderPass(vk, vkDevice, &renderPassParams));
1066 const VkImageViewCreateInfo colorAttViewParams =
1068 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // sType
1072 VK_IMAGE_VIEW_TYPE_2D, // viewType
1073 VK_FORMAT_R8G8B8A8_UNORM, // format
1075 VK_COMPONENT_SWIZZLE_R,
1076 VK_COMPONENT_SWIZZLE_G,
1077 VK_COMPONENT_SWIZZLE_B,
1078 VK_COMPONENT_SWIZZLE_A
1081 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
1084 0u, // baseArrayLayer
1086 }, // subresourceRange
1088 const Unique<VkImageView> colorAttView (createImageView(vk, vkDevice, &colorAttViewParams));
1091 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
1093 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType
1095 (vk::VkPipelineLayoutCreateFlags)0,
1096 0u, // setLayoutCount
1097 DE_NULL, // pSetLayouts
1098 0u, // pushConstantRangeCount
1099 DE_NULL, // pPushConstantRanges
1101 const Unique<VkPipelineLayout> pipelineLayout (createPipelineLayout(vk, vkDevice, &pipelineLayoutParams));
1104 const Unique<VkShaderModule> vertShaderModule (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("vert"), 0));
1105 const Unique<VkShaderModule> fragShaderModule (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("frag"), 0));
1108 const VkSpecializationInfo emptyShaderSpecParams =
1110 0u, // mapEntryCount
1115 const VkPipelineShaderStageCreateInfo shaderStageParams[] =
1118 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // sType
1121 VK_SHADER_STAGE_VERTEX_BIT, // stage
1122 *vertShaderModule, // module
1124 &emptyShaderSpecParams, // pSpecializationInfo
1127 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // sType
1130 VK_SHADER_STAGE_FRAGMENT_BIT, // stage
1131 *fragShaderModule, // module
1133 &emptyShaderSpecParams, // pSpecializationInfo
1136 const VkPipelineDepthStencilStateCreateInfo depthStencilParams =
1138 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // sType
1141 DE_FALSE, // depthTestEnable
1142 DE_FALSE, // depthWriteEnable
1143 VK_COMPARE_OP_ALWAYS, // depthCompareOp
1144 DE_FALSE, // depthBoundsTestEnable
1145 DE_FALSE, // stencilTestEnable
1147 VK_STENCIL_OP_KEEP, // failOp
1148 VK_STENCIL_OP_KEEP, // passOp
1149 VK_STENCIL_OP_KEEP, // depthFailOp
1150 VK_COMPARE_OP_ALWAYS, // compareOp
1156 VK_STENCIL_OP_KEEP, // failOp
1157 VK_STENCIL_OP_KEEP, // passOp
1158 VK_STENCIL_OP_KEEP, // depthFailOp
1159 VK_COMPARE_OP_ALWAYS, // compareOp
1164 -1.0f, // float minDepthBounds;
1165 +1.0f, // float maxDepthBounds;
1167 const VkViewport viewport0 =
1171 (float)renderSize.x(), // width
1172 (float)renderSize.y(), // height
1176 const VkRect2D scissor0 =
1183 (deUint32)renderSize.x(), // width
1184 (deUint32)renderSize.y(), // height
1187 const VkPipelineViewportStateCreateInfo viewportParams =
1189 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // sType
1192 1u, // viewportCount
1193 &viewport0, // pViewports
1195 &scissor0 // pScissors
1197 const VkSampleMask sampleMask = ~0u;
1198 const VkPipelineMultisampleStateCreateInfo multisampleParams =
1200 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // sType
1203 VK_SAMPLE_COUNT_1_BIT, // rasterizationSamples
1204 VK_FALSE, // sampleShadingEnable
1205 0.0f, // minSampleShading
1206 &sampleMask, // sampleMask
1207 VK_FALSE, // alphaToCoverageEnable
1208 VK_FALSE, // alphaToOneEnable
1210 const VkPipelineRasterizationStateCreateInfo rasterParams =
1212 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // sType
1215 VK_TRUE, // depthClampEnable
1216 VK_FALSE, // rasterizerDiscardEnable
1217 VK_POLYGON_MODE_FILL, // polygonMode
1218 VK_CULL_MODE_NONE, // cullMode
1219 VK_FRONT_FACE_COUNTER_CLOCKWISE, // frontFace
1220 VK_FALSE, // depthBiasEnable
1221 0.0f, // depthBiasConstantFactor
1222 0.0f, // depthBiasClamp
1223 0.0f, // depthBiasSlopeFactor
1226 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyParams =
1228 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // sType
1231 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // topology
1232 DE_FALSE, // primitiveRestartEnable
1234 const VkVertexInputBindingDescription vertexBinding0 =
1237 (deUint32)sizeof(tcu::Vec4), // stride
1238 VK_VERTEX_INPUT_RATE_VERTEX, // inputRate
1240 const VkVertexInputAttributeDescription vertexAttrib0 =
1244 VK_FORMAT_R32G32B32A32_SFLOAT, // format
1247 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
1249 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // sType
1252 1u, // vertexBindingDescriptionCount
1253 &vertexBinding0, // pVertexBindingDescriptions
1254 1u, // vertexAttributeDescriptionCount
1255 &vertexAttrib0, // pVertexAttributeDescriptions
1257 const VkPipelineColorBlendAttachmentState attBlendParams =
1259 VK_FALSE, // blendEnable
1260 VK_BLEND_FACTOR_ONE, // srcColorBlendFactor
1261 VK_BLEND_FACTOR_ZERO, // dstColorBlendFactor
1262 VK_BLEND_OP_ADD, // colorBlendOp
1263 VK_BLEND_FACTOR_ONE, // srcAlphaBlendFactor
1264 VK_BLEND_FACTOR_ZERO, // dstAlphaBlendFactor
1265 VK_BLEND_OP_ADD, // alphaBlendOp
1266 (VK_COLOR_COMPONENT_R_BIT|
1267 VK_COLOR_COMPONENT_G_BIT|
1268 VK_COLOR_COMPONENT_B_BIT|
1269 VK_COLOR_COMPONENT_A_BIT), // colorWriteMask
1271 const VkPipelineColorBlendStateCreateInfo blendParams =
1273 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // sType
1276 DE_FALSE, // logicOpEnable
1277 VK_LOGIC_OP_COPY, // logicOp
1278 1u, // attachmentCount
1279 &attBlendParams, // pAttachments
1280 { 0.0f, 0.0f, 0.0f, 0.0f }, // blendConstants[4]
1282 const VkGraphicsPipelineCreateInfo pipelineParams =
1284 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // sType
1287 (deUint32)DE_LENGTH_OF_ARRAY(shaderStageParams), // stageCount
1288 shaderStageParams, // pStages
1289 &vertexInputStateParams, // pVertexInputState
1290 &inputAssemblyParams, // pInputAssemblyState
1291 DE_NULL, // pTessellationState
1292 &viewportParams, // pViewportState
1293 &rasterParams, // pRasterizationState
1294 &multisampleParams, // pMultisampleState
1295 &depthStencilParams, // pDepthStencilState
1296 &blendParams, // pColorBlendState
1297 (const VkPipelineDynamicStateCreateInfo*)DE_NULL, // pDynamicState
1298 *pipelineLayout, // layout
1299 *renderPass, // renderPass
1301 DE_NULL, // basePipelineHandle
1302 0u, // basePipelineIndex
1305 const Unique<VkPipeline> pipeline (createGraphicsPipeline(vk, vkDevice, DE_NULL, &pipelineParams));
1308 const VkFramebufferCreateInfo framebufferParams =
1310 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // sType
1313 *renderPass, // renderPass
1314 1u, // attachmentCount
1315 &*colorAttView, // pAttachments
1316 (deUint32)renderSize.x(), // width
1317 (deUint32)renderSize.y(), // height
1320 const Unique<VkFramebuffer> framebuffer (createFramebuffer(vk, vkDevice, &framebufferParams));
1322 const VkCommandPoolCreateInfo cmdPoolParams =
1324 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType
1326 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags
1327 queueFamilyIndex, // queueFamilyIndex
1329 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
1332 const VkCommandBufferAllocateInfo cmdBufParams =
1334 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType
1337 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level
1340 const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
1342 const VkCommandBufferBeginInfo cmdBufBeginParams =
1344 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType
1347 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1351 VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginParams));
1354 const VkMemoryBarrier vertFlushBarrier =
1356 VK_STRUCTURE_TYPE_MEMORY_BARRIER, // sType
1358 VK_ACCESS_HOST_WRITE_BIT, // srcAccessMask
1359 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, // dstAccessMask
1361 const VkImageMemoryBarrier colorAttBarrier =
1363 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
1365 0u, // srcAccessMask
1366 (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT|
1367 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT), // dstAccessMask
1368 VK_IMAGE_LAYOUT_UNDEFINED, // oldLayout
1369 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout
1370 queueFamilyIndex, // srcQueueFamilyIndex
1371 queueFamilyIndex, // dstQueueFamilyIndex
1374 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
1377 0u, // baseArrayLayer
1379 } // subresourceRange
1381 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, (VkDependencyFlags)0, 1, &vertFlushBarrier, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &colorAttBarrier);
1385 const VkClearValue clearValue = makeClearValueColorF32(clearColor[0],
1389 const VkRenderPassBeginInfo passBeginParams =
1391 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // sType
1393 *renderPass, // renderPass
1394 *framebuffer, // framebuffer
1397 { (deUint32)renderSize.x(), (deUint32)renderSize.y() }
1399 1u, // clearValueCount
1400 &clearValue, // pClearValues
1402 vk.cmdBeginRenderPass(*cmdBuf, &passBeginParams, VK_SUBPASS_CONTENTS_INLINE);
1405 vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
1407 const VkDeviceSize bindingOffset = 0;
1408 vk.cmdBindVertexBuffers(*cmdBuf, 0u, 1u, &vertexBuffer.get(), &bindingOffset);
1410 vk.cmdDraw(*cmdBuf, 3u, 1u, 0u, 0u);
1411 vk.cmdEndRenderPass(*cmdBuf);
1414 const VkImageMemoryBarrier renderFinishBarrier =
1416 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
1418 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // outputMask
1419 VK_ACCESS_TRANSFER_READ_BIT, // inputMask
1420 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // oldLayout
1421 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // newLayout
1422 queueFamilyIndex, // srcQueueFamilyIndex
1423 queueFamilyIndex, // dstQueueFamilyIndex
1426 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
1429 0u, // baseArraySlice
1431 } // subresourceRange
1433 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &renderFinishBarrier);
1437 const VkBufferImageCopy copyParams =
1439 (VkDeviceSize)0u, // bufferOffset
1440 (deUint32)renderSize.x(), // bufferRowLength
1441 (deUint32)renderSize.y(), // bufferImageHeight
1443 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
1445 0u, // baseArrayLayer
1447 }, // imageSubresource
1448 { 0u, 0u, 0u }, // imageOffset
1450 (deUint32)renderSize.x(),
1451 (deUint32)renderSize.y(),
1455 vk.cmdCopyImageToBuffer(*cmdBuf, *image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *readImageBuffer, 1u, ©Params);
1459 const VkBufferMemoryBarrier copyFinishBarrier =
1461 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // sType
1463 VK_ACCESS_TRANSFER_WRITE_BIT, // srcAccessMask
1464 VK_ACCESS_HOST_READ_BIT, // dstAccessMask
1465 queueFamilyIndex, // srcQueueFamilyIndex
1466 queueFamilyIndex, // dstQueueFamilyIndex
1467 *readImageBuffer, // buffer
1469 imageSizeBytes // size
1471 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, ©FinishBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
1474 VK_CHECK(vk.endCommandBuffer(*cmdBuf));
1476 // Upload vertex data
1478 const VkMappedMemoryRange range =
1480 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // sType
1482 vertexBufferMemory->getMemory(), // memory
1484 (VkDeviceSize)sizeof(vertices), // size
1486 void* vertexBufPtr = vertexBufferMemory->getHostPtr();
1488 deMemcpy(vertexBufPtr, &vertices[0], sizeof(vertices));
1489 VK_CHECK(vk.flushMappedMemoryRanges(vkDevice, 1u, &range));
1492 // Submit & wait for completion
1494 const VkFenceCreateInfo fenceParams =
1496 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // sType
1500 const VkSubmitInfo submitInfo =
1502 VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
1504 0u, // waitSemaphoreCount
1505 DE_NULL, // pWaitSemaphores
1506 (const VkPipelineStageFlags*)DE_NULL,
1507 1u, // commandBufferCount
1508 &cmdBuf.get(), // pCommandBuffers
1509 0u, // signalSemaphoreCount
1510 DE_NULL, // pSignalSemaphores
1512 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceParams));
1514 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
1515 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), DE_TRUE, ~0ull));
1518 // Read results, render reference, compare
1520 const tcu::TextureFormat tcuFormat = vk::mapVkFormat(colorFormat);
1521 const VkMappedMemoryRange range =
1523 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // sType
1525 readImageBufferMemory->getMemory(), // memory
1527 imageSizeBytes, // size
1529 const tcu::ConstPixelBufferAccess resultAccess (tcuFormat, renderSize.x(), renderSize.y(), 1, readImageBufferMemory->getHostPtr());
1531 VK_CHECK(vk.invalidateMappedMemoryRanges(vkDevice, 1u, &range));
1534 tcu::TextureLevel refImage (tcuFormat, renderSize.x(), renderSize.y());
1535 const tcu::UVec4 threshold (0u);
1536 const tcu::IVec3 posDeviation (1,1,0);
1538 tcu::clear(refImage.getAccess(), clearColor);
1539 renderReferenceTriangle(refImage.getAccess(), vertices);
1541 if (tcu::intThresholdPositionDeviationCompare(context.getTestContext().getLog(),
1543 "Image comparison result",
1544 refImage.getAccess(),
1549 tcu::COMPARE_LOG_RESULT))
1550 return tcu::TestStatus::pass("Rendering succeeded");
1552 return tcu::TestStatus::fail("Image comparison failed");
1556 return tcu::TestStatus::pass("Rendering succeeded");
1561 tcu::TestCaseGroup* createSmokeTests (tcu::TestContext& testCtx)
1563 de::MovePtr<tcu::TestCaseGroup> smokeTests (new tcu::TestCaseGroup(testCtx, "smoke", "Smoke Tests"));
1565 addFunctionCase (smokeTests.get(), "create_sampler", "", createSamplerTest);
1566 addFunctionCaseWithPrograms (smokeTests.get(), "create_shader", "", createShaderProgs, createShaderModuleTest);
1567 addFunctionCaseWithPrograms (smokeTests.get(), "triangle", "", createTriangleProgs, renderTriangleTest);
1568 addFunctionCaseWithPrograms (smokeTests.get(), "asm_triangle", "", createTriangleAsmProgs, renderTriangleTest);
1569 addFunctionCaseWithPrograms (smokeTests.get(), "asm_triangle_no_opname", "", createProgsNoOpName, renderTriangleTest);
1570 addFunctionCaseWithPrograms (smokeTests.get(), "unused_resolve_attachment", "", createTriangleProgs, renderTriangleUnusedResolveAttachmentTest);
1572 return smokeTests.release();