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"
39 #include "vkCmdUtil.hpp"
40 #include "vkObjUtil.hpp"
42 #include "tcuTestLog.hpp"
43 #include "tcuFormatUtil.hpp"
44 #include "tcuTextureUtil.hpp"
45 #include "tcuImageCompare.hpp"
47 #include "rrRenderer.hpp"
49 #include "deUniquePtr.hpp"
64 tcu::TestStatus createSamplerTest (Context& context)
66 const VkDevice vkDevice = context.getDevice();
67 const DeviceInterface& vk = context.getDeviceInterface();
70 const struct VkSamplerCreateInfo samplerInfo =
72 VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, // sType
75 VK_FILTER_NEAREST, // magFilter
76 VK_FILTER_NEAREST, // minFilter
77 VK_SAMPLER_MIPMAP_MODE_NEAREST, // mipmapMode
78 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // addressModeU
79 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // addressModeV
80 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // addressModeW
82 VK_FALSE, // anisotropyEnable
83 1.0f, // maxAnisotropy
84 DE_FALSE, // compareEnable
85 VK_COMPARE_OP_ALWAYS, // compareOp
88 VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK, // borderColor
89 VK_FALSE, // unnormalizedCoords
92 Move<VkSampler> tmpSampler = createSampler(vk, vkDevice, &samplerInfo);
93 Move<VkSampler> tmp2Sampler;
95 tmp2Sampler = tmpSampler;
97 const Unique<VkSampler> sampler (tmp2Sampler);
100 return tcu::TestStatus::pass("Creating sampler succeeded");
103 void createShaderProgs (SourceCollections& dst)
105 dst.glslSources.add("test") << glu::VertexSource(
107 "layout(location = 0) in highp vec4 a_position;\n"
108 "void main (void) { gl_Position = a_position; }\n");
111 tcu::TestStatus createShaderModuleTest (Context& context)
113 const VkDevice vkDevice = context.getDevice();
114 const DeviceInterface& vk = context.getDeviceInterface();
115 const Unique<VkShaderModule> shader (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("test"), 0));
117 return tcu::TestStatus::pass("Creating shader module succeeded");
120 void createTriangleAsmProgs (SourceCollections& dst)
122 dst.spirvAsmSources.add("vert") <<
123 " OpCapability Shader\n"
124 "%1 = OpExtInstImport \"GLSL.std.450\"\n"
125 " OpMemoryModel Logical GLSL450\n"
126 " OpEntryPoint Vertex %4 \"main\" %10 %12 %16 %17\n"
127 " OpSource ESSL 300\n"
128 " OpName %4 \"main\"\n"
129 " OpName %10 \"gl_Position\"\n"
130 " OpName %12 \"a_position\"\n"
131 " OpName %16 \"gl_VertexIndex\"\n"
132 " OpName %17 \"gl_InstanceIndex\"\n"
133 " OpDecorate %10 BuiltIn Position\n"
134 " OpDecorate %12 Location 0\n"
135 " OpDecorate %16 BuiltIn VertexIndex\n"
136 " OpDecorate %17 BuiltIn InstanceIndex\n"
138 "%3 = OpTypeFunction %2\n"
139 "%7 = OpTypeFloat 32\n"
140 "%8 = OpTypeVector %7 4\n"
141 "%9 = OpTypePointer Output %8\n"
142 "%10 = OpVariable %9 Output\n"
143 "%11 = OpTypePointer Input %8\n"
144 "%12 = OpVariable %11 Input\n"
145 "%14 = OpTypeInt 32 1\n"
146 "%15 = OpTypePointer Input %14\n"
147 "%16 = OpVariable %15 Input\n"
148 "%17 = OpVariable %15 Input\n"
149 "%4 = OpFunction %2 None %3\n"
151 "%13 = OpLoad %8 %12\n"
157 dst.spirvAsmSources.add("frag") <<
158 " OpCapability Shader\n"
159 "%1 = OpExtInstImport \"GLSL.std.450\"\n"
160 " OpMemoryModel Logical GLSL450\n"
161 " OpEntryPoint Fragment %4 \"main\" %10\n"
162 " OpExecutionMode %4 OriginUpperLeft\n"
163 " OpSource ESSL 300\n"
164 " OpName %4 \"main\"\n"
165 " OpName %10 \"o_color\"\n"
166 " OpDecorate %10 RelaxedPrecision\n"
167 " OpDecorate %10 Location 0\n"
169 "%3 = OpTypeFunction %2\n"
170 "%7 = OpTypeFloat 32\n"
171 "%8 = OpTypeVector %7 4\n"
172 "%9 = OpTypePointer Output %8\n"
173 "%10 = OpVariable %9 Output\n"
174 "%11 = OpConstant %7 1065353216\n"
175 "%12 = OpConstant %7 0\n"
176 "%13 = OpConstantComposite %8 %11 %12 %11 %11\n"
177 "%4 = OpFunction %2 None %3\n"
186 void createTriangleProgs (SourceCollections& dst)
188 dst.glslSources.add("vert") << glu::VertexSource(
190 "layout(location = 0) in highp vec4 a_position;\n"
191 "void main (void) { gl_Position = a_position; }\n");
192 dst.glslSources.add("frag") << glu::FragmentSource(
194 "layout(location = 0) out lowp vec4 o_color;\n"
195 "void main (void) { o_color = vec4(1.0, 0.0, 1.0, 1.0); }\n");
198 void createProgsNoOpName (SourceCollections& dst)
200 dst.spirvAsmSources.add("vert") <<
201 "OpCapability Shader\n"
202 "%1 = OpExtInstImport \"GLSL.std.450\"\n"
203 "OpMemoryModel Logical GLSL450\n"
204 "OpEntryPoint Vertex %4 \"main\" %20 %22 %26\n"
205 "OpSource ESSL 310\n"
206 "OpMemberDecorate %18 0 BuiltIn Position\n"
207 "OpMemberDecorate %18 1 BuiltIn PointSize\n"
208 "OpDecorate %18 Block\n"
209 "OpDecorate %22 Location 0\n"
210 "OpDecorate %26 Location 2\n"
212 "%3 = OpTypeFunction %2\n"
213 "%6 = OpTypeFloat 32\n"
214 "%7 = OpTypeVector %6 4\n"
215 "%8 = OpTypeStruct %7\n"
216 "%9 = OpTypePointer Function %8\n"
217 "%11 = OpTypeInt 32 1\n"
218 "%12 = OpConstant %11 0\n"
219 "%13 = OpConstant %6 1\n"
220 "%14 = OpConstant %6 0\n"
221 "%15 = OpConstantComposite %7 %13 %14 %13 %13\n"
222 "%16 = OpTypePointer Function %7\n"
223 "%18 = OpTypeStruct %7 %6\n"
224 "%19 = OpTypePointer Output %18\n"
225 "%20 = OpVariable %19 Output\n"
226 "%21 = OpTypePointer Input %7\n"
227 "%22 = OpVariable %21 Input\n"
228 "%24 = OpTypePointer Output %7\n"
229 "%26 = OpVariable %24 Output\n"
230 "%4 = OpFunction %2 None %3\n"
232 "%10 = OpVariable %9 Function\n"
233 "%17 = OpAccessChain %16 %10 %12\n"
235 "%23 = OpLoad %7 %22\n"
236 "%25 = OpAccessChain %24 %20 %12\n"
238 "%27 = OpAccessChain %16 %10 %12\n"
239 "%28 = OpLoad %7 %27\n"
243 dst.spirvAsmSources.add("frag") <<
244 "OpCapability Shader\n"
245 "%1 = OpExtInstImport \"GLSL.std.450\"\n"
246 "OpMemoryModel Logical GLSL450\n"
247 "OpEntryPoint Fragment %4 \"main\" %9 %11\n"
248 "OpExecutionMode %4 OriginUpperLeft\n"
249 "OpSource ESSL 310\n"
250 "OpDecorate %9 RelaxedPrecision\n"
251 "OpDecorate %9 Location 0\n"
252 "OpDecorate %11 Location 2\n"
254 "%3 = OpTypeFunction %2\n"
255 "%6 = OpTypeFloat 32\n"
256 "%7 = OpTypeVector %6 4\n"
257 "%8 = OpTypePointer Output %7\n"
258 "%9 = OpVariable %8 Output\n"
259 "%10 = OpTypePointer Input %7\n"
260 "%11 = OpVariable %10 Input\n"
261 "%4 = OpFunction %2 None %3\n"
263 "%12 = OpLoad %7 %11\n"
269 class RefVertexShader : public rr::VertexShader
272 RefVertexShader (void)
273 : rr::VertexShader(1, 0)
275 m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
278 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
280 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
282 packets[packetNdx]->position = rr::readVertexAttribFloat(inputs[0],
283 packets[packetNdx]->instanceNdx,
284 packets[packetNdx]->vertexNdx);
289 class RefFragmentShader : public rr::FragmentShader
292 RefFragmentShader (void)
293 : rr::FragmentShader(0, 1)
295 m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
298 void shadeFragments (rr::FragmentPacket*, const int numPackets, const rr::FragmentShadingContext& context) const
300 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
302 for (int fragNdx = 0; fragNdx < rr::NUM_FRAGMENTS_PER_PACKET; ++fragNdx)
304 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f));
310 void renderReferenceTriangle (const tcu::PixelBufferAccess& dst, const tcu::Vec4 (&vertices)[3], const int subpixelBits)
312 const RefVertexShader vertShader;
313 const RefFragmentShader fragShader;
314 const rr::Program program (&vertShader, &fragShader);
315 const rr::MultisamplePixelBufferAccess colorBuffer = rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(dst);
316 const rr::RenderTarget renderTarget (colorBuffer);
317 const rr::RenderState renderState ((rr::ViewportState(colorBuffer)), subpixelBits, rr::VIEWPORTORIENTATION_UPPER_LEFT);
318 const rr::Renderer renderer;
319 const rr::VertexAttrib vertexAttribs[] =
321 rr::VertexAttrib(rr::VERTEXATTRIBTYPE_FLOAT, 4, sizeof(tcu::Vec4), 0, vertices[0].getPtr())
324 renderer.draw(rr::DrawCommand(renderState,
327 DE_LENGTH_OF_ARRAY(vertexAttribs),
329 rr::PrimitiveList(rr::PRIMITIVETYPE_TRIANGLES, DE_LENGTH_OF_ARRAY(vertices), 0)));
332 tcu::TestStatus renderTriangleTest (Context& context)
334 const VkDevice vkDevice = context.getDevice();
335 const DeviceInterface& vk = context.getDeviceInterface();
336 const VkQueue queue = context.getUniversalQueue();
337 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
338 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
339 const tcu::IVec2 renderSize (256, 256);
340 const VkFormat colorFormat = VK_FORMAT_R8G8B8A8_UNORM;
341 const tcu::Vec4 clearColor (0.125f, 0.25f, 0.75f, 1.0f);
343 const tcu::Vec4 vertices[] =
345 tcu::Vec4(-0.5f, -0.5f, 0.0f, 1.0f),
346 tcu::Vec4(+0.5f, -0.5f, 0.0f, 1.0f),
347 tcu::Vec4( 0.0f, +0.5f, 0.0f, 1.0f)
350 const VkBufferCreateInfo vertexBufferParams =
352 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // sType
355 (VkDeviceSize)sizeof(vertices), // size
356 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // usage
357 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
358 1u, // queueFamilyIndexCount
359 &queueFamilyIndex, // pQueueFamilyIndices
361 const Unique<VkBuffer> vertexBuffer (createBuffer(vk, vkDevice, &vertexBufferParams));
362 const UniquePtr<Allocation> vertexBufferMemory (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible));
364 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferMemory->getMemory(), vertexBufferMemory->getOffset()));
366 const VkDeviceSize imageSizeBytes = (VkDeviceSize)(sizeof(deUint32)*renderSize.x()*renderSize.y());
367 const VkBufferCreateInfo readImageBufferParams =
369 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // sType
371 (VkBufferCreateFlags)0u, // flags
372 imageSizeBytes, // size
373 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // usage
374 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
375 1u, // queueFamilyIndexCount
376 &queueFamilyIndex, // pQueueFamilyIndices
378 const Unique<VkBuffer> readImageBuffer (createBuffer(vk, vkDevice, &readImageBufferParams));
379 const UniquePtr<Allocation> readImageBufferMemory (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *readImageBuffer), MemoryRequirement::HostVisible));
381 VK_CHECK(vk.bindBufferMemory(vkDevice, *readImageBuffer, readImageBufferMemory->getMemory(), readImageBufferMemory->getOffset()));
383 const VkImageCreateInfo imageParams =
385 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // sType
388 VK_IMAGE_TYPE_2D, // imageType
389 VK_FORMAT_R8G8B8A8_UNORM, // format
390 { (deUint32)renderSize.x(), (deUint32)renderSize.y(), 1 }, // extent
393 VK_SAMPLE_COUNT_1_BIT, // samples
394 VK_IMAGE_TILING_OPTIMAL, // tiling
395 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // usage
396 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
397 1u, // queueFamilyIndexCount
398 &queueFamilyIndex, // pQueueFamilyIndices
399 VK_IMAGE_LAYOUT_UNDEFINED, // initialLayout
402 const Unique<VkImage> image (createImage(vk, vkDevice, &imageParams));
403 const UniquePtr<Allocation> imageMemory (memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any));
405 VK_CHECK(vk.bindImageMemory(vkDevice, *image, imageMemory->getMemory(), imageMemory->getOffset()));
407 const Unique<VkRenderPass> renderPass (makeRenderPass(vk, vkDevice, VK_FORMAT_R8G8B8A8_UNORM));
409 const VkImageViewCreateInfo colorAttViewParams =
411 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // sType
415 VK_IMAGE_VIEW_TYPE_2D, // viewType
416 VK_FORMAT_R8G8B8A8_UNORM, // format
418 VK_COMPONENT_SWIZZLE_R,
419 VK_COMPONENT_SWIZZLE_G,
420 VK_COMPONENT_SWIZZLE_B,
421 VK_COMPONENT_SWIZZLE_A
424 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
427 0u, // baseArrayLayer
429 }, // subresourceRange
431 const Unique<VkImageView> colorAttView (createImageView(vk, vkDevice, &colorAttViewParams));
434 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
436 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType
438 (vk::VkPipelineLayoutCreateFlags)0,
439 0u, // setLayoutCount
440 DE_NULL, // pSetLayouts
441 0u, // pushConstantRangeCount
442 DE_NULL, // pPushConstantRanges
444 const Unique<VkPipelineLayout> pipelineLayout (createPipelineLayout(vk, vkDevice, &pipelineLayoutParams));
447 const Unique<VkShaderModule> vertShaderModule (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("vert"), 0));
448 const Unique<VkShaderModule> fragShaderModule (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("frag"), 0));
451 const std::vector<VkViewport> viewports (1, makeViewport(renderSize));
452 const std::vector<VkRect2D> scissors (1, makeRect2D(renderSize));
454 const Unique<VkPipeline> pipeline (makeGraphicsPipeline(vk, // const DeviceInterface& vk
455 vkDevice, // const VkDevice device
456 *pipelineLayout, // const VkPipelineLayout pipelineLayout
457 *vertShaderModule, // const VkShaderModule vertexShaderModule
458 DE_NULL, // const VkShaderModule tessellationControlModule
459 DE_NULL, // const VkShaderModule tessellationEvalModule
460 DE_NULL, // const VkShaderModule geometryShaderModule
461 *fragShaderModule, // const VkShaderModule fragmentShaderModule
462 *renderPass, // const VkRenderPass renderPass
463 viewports, // const std::vector<VkViewport>& viewports
464 scissors)); // const std::vector<VkRect2D>& scissors
467 const VkFramebufferCreateInfo framebufferParams =
469 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // sType
472 *renderPass, // renderPass
473 1u, // attachmentCount
474 &*colorAttView, // pAttachments
475 (deUint32)renderSize.x(), // width
476 (deUint32)renderSize.y(), // height
479 const Unique<VkFramebuffer> framebuffer (createFramebuffer(vk, vkDevice, &framebufferParams));
481 const VkCommandPoolCreateInfo cmdPoolParams =
483 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType
485 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags
486 queueFamilyIndex, // queueFamilyIndex
488 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
491 const VkCommandBufferAllocateInfo cmdBufParams =
493 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType
496 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level
499 const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
502 beginCommandBuffer(vk, *cmdBuf);
505 const VkMemoryBarrier vertFlushBarrier =
507 VK_STRUCTURE_TYPE_MEMORY_BARRIER, // sType
509 VK_ACCESS_HOST_WRITE_BIT, // srcAccessMask
510 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, // dstAccessMask
512 const VkImageMemoryBarrier colorAttBarrier =
514 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
517 (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT|
518 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT), // dstAccessMask
519 VK_IMAGE_LAYOUT_UNDEFINED, // oldLayout
520 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout
521 queueFamilyIndex, // srcQueueFamilyIndex
522 queueFamilyIndex, // dstQueueFamilyIndex
525 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
528 0u, // baseArrayLayer
530 } // subresourceRange
532 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);
535 beginRenderPass(vk, *cmdBuf, *renderPass, *framebuffer, makeRect2D(0, 0, renderSize.x(), renderSize.y()), clearColor);
537 vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
539 const VkDeviceSize bindingOffset = 0;
540 vk.cmdBindVertexBuffers(*cmdBuf, 0u, 1u, &vertexBuffer.get(), &bindingOffset);
542 vk.cmdDraw(*cmdBuf, 3u, 1u, 0u, 0u);
543 endRenderPass(vk, *cmdBuf);
544 copyImageToBuffer(vk, *cmdBuf, *image, *readImageBuffer, renderSize);
545 endCommandBuffer(vk, *cmdBuf);
547 // Upload vertex data
548 deMemcpy(vertexBufferMemory->getHostPtr(), &vertices[0], sizeof(vertices));
549 flushAlloc(vk, vkDevice, *vertexBufferMemory);
551 // Submit & wait for completion
552 submitCommandsAndWait(vk, vkDevice, queue, cmdBuf.get());
554 // Read results, render reference, compare
556 const tcu::TextureFormat tcuFormat = vk::mapVkFormat(colorFormat);
557 const tcu::ConstPixelBufferAccess resultAccess (tcuFormat, renderSize.x(), renderSize.y(), 1, readImageBufferMemory->getHostPtr());
559 invalidateAlloc(vk, vkDevice, *readImageBufferMemory);
562 tcu::TextureLevel refImage (tcuFormat, renderSize.x(), renderSize.y());
563 const tcu::UVec4 threshold (0u);
564 const tcu::IVec3 posDeviation (1,1,0);
566 tcu::clear(refImage.getAccess(), clearColor);
567 renderReferenceTriangle(refImage.getAccess(), vertices, context.getDeviceProperties().limits.subPixelPrecisionBits);
569 if (tcu::intThresholdPositionDeviationCompare(context.getTestContext().getLog(),
571 "Image comparison result",
572 refImage.getAccess(),
577 tcu::COMPARE_LOG_RESULT))
578 return tcu::TestStatus::pass("Rendering succeeded");
580 return tcu::TestStatus::fail("Image comparison failed");
584 return tcu::TestStatus::pass("Rendering succeeded");
587 struct VoidVulkanStruct
589 VkStructureType sType;
593 tcu::TestStatus renderTriangleUnusedResolveAttachmentTest (Context& context)
595 const VkDevice vkDevice = context.getDevice();
596 const DeviceInterface& vk = context.getDeviceInterface();
597 const VkQueue queue = context.getUniversalQueue();
598 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
599 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
600 const tcu::IVec2 renderSize (256, 256);
601 const VkFormat colorFormat = VK_FORMAT_R8G8B8A8_UNORM;
602 const tcu::Vec4 clearColor (0.125f, 0.25f, 0.75f, 1.0f);
604 const tcu::Vec4 vertices[] =
606 tcu::Vec4(-0.5f, -0.5f, 0.0f, 1.0f),
607 tcu::Vec4(+0.5f, -0.5f, 0.0f, 1.0f),
608 tcu::Vec4( 0.0f, +0.5f, 0.0f, 1.0f)
611 const VkBufferCreateInfo vertexBufferParams =
613 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // sType
616 (VkDeviceSize)sizeof(vertices), // size
617 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // usage
618 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
619 1u, // queueFamilyIndexCount
620 &queueFamilyIndex, // pQueueFamilyIndices
622 const Unique<VkBuffer> vertexBuffer (createBuffer(vk, vkDevice, &vertexBufferParams));
623 const UniquePtr<Allocation> vertexBufferMemory (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible));
625 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferMemory->getMemory(), vertexBufferMemory->getOffset()));
627 const VkDeviceSize imageSizeBytes = (VkDeviceSize)(sizeof(deUint32)*renderSize.x()*renderSize.y());
628 const VkBufferCreateInfo readImageBufferParams =
630 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // sType
632 (VkBufferCreateFlags)0u, // flags
633 imageSizeBytes, // size
634 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // usage
635 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
636 1u, // queueFamilyIndexCount
637 &queueFamilyIndex, // pQueueFamilyIndices
639 const Unique<VkBuffer> readImageBuffer (createBuffer(vk, vkDevice, &readImageBufferParams));
640 const UniquePtr<Allocation> readImageBufferMemory (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *readImageBuffer), MemoryRequirement::HostVisible));
642 VK_CHECK(vk.bindBufferMemory(vkDevice, *readImageBuffer, readImageBufferMemory->getMemory(), readImageBufferMemory->getOffset()));
644 const VkImageCreateInfo imageParams =
646 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // sType
649 VK_IMAGE_TYPE_2D, // imageType
650 VK_FORMAT_R8G8B8A8_UNORM, // format
651 { (deUint32)renderSize.x(), (deUint32)renderSize.y(), 1 }, // extent
654 VK_SAMPLE_COUNT_1_BIT, // samples
655 VK_IMAGE_TILING_OPTIMAL, // tiling
656 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // usage
657 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
658 1u, // queueFamilyIndexCount
659 &queueFamilyIndex, // pQueueFamilyIndices
660 VK_IMAGE_LAYOUT_UNDEFINED, // initialLayout
663 const Unique<VkImage> image (createImage(vk, vkDevice, &imageParams));
664 const UniquePtr<Allocation> imageMemory (memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any));
666 VK_CHECK(vk.bindImageMemory(vkDevice, *image, imageMemory->getMemory(), imageMemory->getOffset()));
668 const VkAttachmentDescription colorAttDesc =
671 VK_FORMAT_R8G8B8A8_UNORM, // format
672 VK_SAMPLE_COUNT_1_BIT, // samples
673 VK_ATTACHMENT_LOAD_OP_CLEAR, // loadOp
674 VK_ATTACHMENT_STORE_OP_STORE, // storeOp
675 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // stencilLoadOp
676 VK_ATTACHMENT_STORE_OP_DONT_CARE, // stencilStoreOp
677 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // initialLayout
678 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // finalLayout
680 const VkAttachmentReference colorAttRef =
683 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // layout
685 const VkAttachmentReference resolveAttRef =
687 VK_ATTACHMENT_UNUSED,
688 VK_IMAGE_LAYOUT_GENERAL
690 const VkSubpassDescription subpassDesc =
692 (VkSubpassDescriptionFlags)0u, // flags
693 VK_PIPELINE_BIND_POINT_GRAPHICS, // pipelineBindPoint
694 0u, // inputAttachmentCount
695 DE_NULL, // pInputAttachments
696 1u, // colorAttachmentCount
697 &colorAttRef, // pColorAttachments
698 &resolveAttRef, // pResolveAttachments
699 DE_NULL, // depthStencilAttachment
700 0u, // preserveAttachmentCount
701 DE_NULL, // pPreserveAttachments
703 const VkRenderPassCreateInfo renderPassParams =
705 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // sType
708 1u, // attachmentCount
709 &colorAttDesc, // pAttachments
711 &subpassDesc, // pSubpasses
712 0u, // dependencyCount
713 DE_NULL, // pDependencies
715 const Unique<VkRenderPass> renderPass (createRenderPass(vk, vkDevice, &renderPassParams));
717 const VkImageViewCreateInfo colorAttViewParams =
719 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // sType
723 VK_IMAGE_VIEW_TYPE_2D, // viewType
724 VK_FORMAT_R8G8B8A8_UNORM, // format
726 VK_COMPONENT_SWIZZLE_R,
727 VK_COMPONENT_SWIZZLE_G,
728 VK_COMPONENT_SWIZZLE_B,
729 VK_COMPONENT_SWIZZLE_A
732 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
735 0u, // baseArrayLayer
737 }, // subresourceRange
739 const Unique<VkImageView> colorAttView (createImageView(vk, vkDevice, &colorAttViewParams));
742 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
744 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType
746 (vk::VkPipelineLayoutCreateFlags)0,
747 0u, // setLayoutCount
748 DE_NULL, // pSetLayouts
749 0u, // pushConstantRangeCount
750 DE_NULL, // pPushConstantRanges
752 const Unique<VkPipelineLayout> pipelineLayout (createPipelineLayout(vk, vkDevice, &pipelineLayoutParams));
755 const Unique<VkShaderModule> vertShaderModule (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("vert"), 0));
756 const Unique<VkShaderModule> fragShaderModule (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("frag"), 0));
759 const std::vector<VkViewport> viewports (1, makeViewport(renderSize));
760 const std::vector<VkRect2D> scissors (1, makeRect2D(renderSize));
762 const Unique<VkPipeline> pipeline (makeGraphicsPipeline(vk, // const DeviceInterface& vk
763 vkDevice, // const VkDevice device
764 *pipelineLayout, // const VkPipelineLayout pipelineLayout
765 *vertShaderModule, // const VkShaderModule vertexShaderModule
766 DE_NULL, // const VkShaderModule tessellationControlShaderModule
767 DE_NULL, // const VkShaderModule tessellationEvalShaderModule
768 DE_NULL, // const VkShaderModule geometryShaderModule
769 *fragShaderModule, // const VkShaderModule fragmentShaderModule
770 *renderPass, // const VkRenderPass renderPass
771 viewports, // const std::vector<VkViewport>& viewports
772 scissors)); // const std::vector<VkRect2D>& scissors
775 const VkFramebufferCreateInfo framebufferParams =
777 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // sType
780 *renderPass, // renderPass
781 1u, // attachmentCount
782 &*colorAttView, // pAttachments
783 (deUint32)renderSize.x(), // width
784 (deUint32)renderSize.y(), // height
787 const Unique<VkFramebuffer> framebuffer (createFramebuffer(vk, vkDevice, &framebufferParams));
789 const VkCommandPoolCreateInfo cmdPoolParams =
791 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType
793 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags
794 queueFamilyIndex, // queueFamilyIndex
796 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams));
799 const VkCommandBufferAllocateInfo cmdBufParams =
801 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType
804 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level
807 const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
810 beginCommandBuffer(vk, *cmdBuf);
813 const VkMemoryBarrier vertFlushBarrier =
815 VK_STRUCTURE_TYPE_MEMORY_BARRIER, // sType
817 VK_ACCESS_HOST_WRITE_BIT, // srcAccessMask
818 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, // dstAccessMask
820 const VkImageMemoryBarrier colorAttBarrier =
822 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
825 (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT|
826 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT), // dstAccessMask
827 VK_IMAGE_LAYOUT_UNDEFINED, // oldLayout
828 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout
829 queueFamilyIndex, // srcQueueFamilyIndex
830 queueFamilyIndex, // dstQueueFamilyIndex
833 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
836 0u, // baseArrayLayer
838 } // subresourceRange
840 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);
843 beginRenderPass(vk, *cmdBuf, *renderPass, *framebuffer, makeRect2D(0, 0, renderSize.x(), renderSize.y()), clearColor);
845 vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
847 const VkDeviceSize bindingOffset = 0;
848 vk.cmdBindVertexBuffers(*cmdBuf, 0u, 1u, &vertexBuffer.get(), &bindingOffset);
850 vk.cmdDraw(*cmdBuf, 3u, 1u, 0u, 0u);
851 endRenderPass(vk, *cmdBuf);
852 copyImageToBuffer(vk, *cmdBuf, *image, *readImageBuffer, renderSize);
853 endCommandBuffer(vk, *cmdBuf);
855 // Upload vertex data
856 deMemcpy(vertexBufferMemory->getHostPtr(), &vertices[0], sizeof(vertices));
857 flushAlloc(vk, vkDevice, *vertexBufferMemory);
859 // Submit & wait for completion
860 submitCommandsAndWait(vk, vkDevice, queue, cmdBuf.get());
862 // Read results, render reference, compare
864 const tcu::TextureFormat tcuFormat = vk::mapVkFormat(colorFormat);
865 const tcu::ConstPixelBufferAccess resultAccess (tcuFormat, renderSize.x(), renderSize.y(), 1, readImageBufferMemory->getHostPtr());
867 invalidateAlloc(vk, vkDevice, *readImageBufferMemory);
870 tcu::TextureLevel refImage (tcuFormat, renderSize.x(), renderSize.y());
871 const tcu::UVec4 threshold (0u);
872 const tcu::IVec3 posDeviation (1,1,0);
874 tcu::clear(refImage.getAccess(), clearColor);
875 renderReferenceTriangle(refImage.getAccess(), vertices, context.getDeviceProperties().limits.subPixelPrecisionBits);
877 if (tcu::intThresholdPositionDeviationCompare(context.getTestContext().getLog(),
879 "Image comparison result",
880 refImage.getAccess(),
885 tcu::COMPARE_LOG_RESULT))
886 return tcu::TestStatus::pass("Rendering succeeded");
888 return tcu::TestStatus::fail("Image comparison failed");
892 return tcu::TestStatus::pass("Rendering succeeded");
897 tcu::TestCaseGroup* createSmokeTests (tcu::TestContext& testCtx)
899 de::MovePtr<tcu::TestCaseGroup> smokeTests (new tcu::TestCaseGroup(testCtx, "smoke", "Smoke Tests"));
901 addFunctionCase (smokeTests.get(), "create_sampler", "", createSamplerTest);
902 addFunctionCaseWithPrograms (smokeTests.get(), "create_shader", "", createShaderProgs, createShaderModuleTest);
903 addFunctionCaseWithPrograms (smokeTests.get(), "triangle", "", createTriangleProgs, renderTriangleTest);
904 addFunctionCaseWithPrograms (smokeTests.get(), "asm_triangle", "", createTriangleAsmProgs, renderTriangleTest);
905 addFunctionCaseWithPrograms (smokeTests.get(), "asm_triangle_no_opname", "", createProgsNoOpName, renderTriangleTest);
906 addFunctionCaseWithPrograms (smokeTests.get(), "unused_resolve_attachment", "", createTriangleProgs, renderTriangleUnusedResolveAttachmentTest);
908 return smokeTests.release();