DO NOT MERGE Do not require signed zero support in ldexp tests() am: 5b076d99a8 ...
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / api / vktApiSmokeTests.cpp
1 /*-------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 Google Inc.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and/or associated documentation files (the
9  * "Materials"), to deal in the Materials without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Materials, and to
12  * permit persons to whom the Materials are furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice(s) and this permission notice shall be
16  * included in all copies or substantial portions of the Materials.
17  *
18  * The Materials are Confidential Information as defined by the
19  * Khronos Membership Agreement until designated non-confidential by
20  * Khronos, at which point this condition clause shall be removed.
21  *
22  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
29  *
30  *//*!
31  * \file
32  * \brief Simple Smoke Tests
33  *//*--------------------------------------------------------------------*/
34
35 #include "vktApiTests.hpp"
36
37 #include "vktTestCaseUtil.hpp"
38
39 #include "vkDefs.hpp"
40 #include "vkPlatform.hpp"
41 #include "vkStrUtil.hpp"
42 #include "vkRef.hpp"
43 #include "vkRefUtil.hpp"
44 #include "vkQueryUtil.hpp"
45 #include "vkMemUtil.hpp"
46 #include "vkDeviceUtil.hpp"
47 #include "vkPrograms.hpp"
48 #include "vkTypeUtil.hpp"
49
50 #include "tcuTestLog.hpp"
51 #include "tcuFormatUtil.hpp"
52
53 #include "deUniquePtr.hpp"
54
55 namespace vkt
56 {
57 namespace api
58 {
59
60 namespace
61 {
62
63 using namespace vk;
64 using std::vector;
65 using tcu::TestLog;
66 using de::UniquePtr;
67
68 tcu::TestStatus createSamplerTest (Context& context)
69 {
70         const VkDevice                  vkDevice        = context.getDevice();
71         const DeviceInterface&  vk                      = context.getDeviceInterface();
72
73         {
74                 const struct VkSamplerCreateInfo                samplerInfo     =
75                 {
76                         VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,          // sType
77                         DE_NULL,                                                                        // pNext
78                         0u,                                                                                     // flags
79                         VK_FILTER_NEAREST,                                                      // magFilter
80                         VK_FILTER_NEAREST,                                                      // minFilter
81                         VK_SAMPLER_MIPMAP_MODE_BASE,                            // mipmapMode
82                         VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,          // addressModeU
83                         VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,          // addressModeV
84                         VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,          // addressModeW
85                         0.0f,                                                                           // mipLodBias
86                         1.0f,                                                                           // maxAnisotropy
87                         DE_FALSE,                                                                       // compareEnable
88                         VK_COMPARE_OP_ALWAYS,                                           // compareOp
89                         0.0f,                                                                           // minLod
90                         0.0f,                                                                           // maxLod
91                         VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,        // borderColor
92                         VK_FALSE,                                                                       // unnormalizedCoords
93                 };
94
95                 Move<VkSampler>                 tmpSampler      = createSampler(vk, vkDevice, &samplerInfo);
96                 Move<VkSampler>                 tmp2Sampler;
97
98                 tmp2Sampler = tmpSampler;
99
100                 const Unique<VkSampler> sampler         (tmp2Sampler);
101         }
102
103         return tcu::TestStatus::pass("Creating sampler succeeded");
104 }
105
106 void createShaderProgs (SourceCollections& dst)
107 {
108         dst.glslSources.add("test") << glu::VertexSource(
109                 "#version 300 es\n"
110                 "in highp vec4 a_position;\n"
111                 "void main (void) { gl_Position = a_position; }\n");
112 }
113
114 tcu::TestStatus createShaderModuleTest (Context& context)
115 {
116         const VkDevice                                  vkDevice        = context.getDevice();
117         const DeviceInterface&                  vk                      = context.getDeviceInterface();
118         const Unique<VkShaderModule>    shader          (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("test"), 0));
119
120         return tcu::TestStatus::pass("Creating shader module succeeded");
121 }
122
123 void createTriangleAsmProgs (SourceCollections& dst)
124 {
125         dst.spirvAsmSources.add("vert") <<
126                 "                OpCapability Shader\n"
127                 "%1 =    OpExtInstImport \"GLSL.std.450\"\n"
128                 "                OpMemoryModel Logical GLSL450\n"
129                 "                OpEntryPoint Vertex %4 \"main\" %10 %12 %16 %17\n"
130                 "                OpSource ESSL 300\n"
131                 "                OpName %4 \"main\"\n"
132                 "                OpName %10 \"gl_Position\"\n"
133                 "                OpName %12 \"a_position\"\n"
134                 "                OpName %16 \"gl_VertexID\"\n"
135                 "                OpName %17 \"gl_InstanceID\"\n"
136                 "                OpDecorate %10 BuiltIn Position\n"
137                 "                OpDecorate %12 Location 0\n"
138                 "                OpDecorate %16 BuiltIn VertexId\n"
139                 "                OpDecorate %17 BuiltIn InstanceId\n"
140                 "%2 =    OpTypeVoid\n"
141                 "%3 =    OpTypeFunction %2\n"
142                 "%7 =    OpTypeFloat 32\n"
143                 "%8 =    OpTypeVector %7 4\n"
144                 "%9 =    OpTypePointer Output %8\n"
145                 "%10 =   OpVariable %9 Output\n"
146                 "%11 =   OpTypePointer Input %8\n"
147                 "%12 =   OpVariable %11 Input\n"
148                 "%14 =   OpTypeInt 32 1\n"
149                 "%15 =   OpTypePointer Input %14\n"
150                 "%16 =   OpVariable %15 Input\n"
151                 "%17 =   OpVariable %15 Input\n"
152                 "%4 =    OpFunction %2 None %3\n"
153                 "%5 =    OpLabel\n"
154                 "%13 =   OpLoad %8 %12\n"
155                 "                OpStore %10 %13\n"
156                 "                OpBranch %6\n"
157                 "%6 =    OpLabel\n"
158                 "                OpReturn\n"
159                 "                OpFunctionEnd\n";
160         dst.spirvAsmSources.add("frag") <<
161                 "               OpCapability Shader\n"
162                 "%1 =   OpExtInstImport \"GLSL.std.450\"\n"
163                 "               OpMemoryModel Logical GLSL450\n"
164                 "               OpEntryPoint Fragment %4 \"main\" %10\n"
165                 "               OpExecutionMode %4 OriginLowerLeft\n"
166                 "               OpSource ESSL 300\n"
167                 "               OpName %4 \"main\"\n"
168                 "               OpName %10 \"o_color\"\n"
169                 "               OpDecorate %10 RelaxedPrecision\n"
170                 "               OpDecorate %10 Location 0\n"
171                 "%2 =   OpTypeVoid\n"
172                 "%3 =   OpTypeFunction %2\n"
173                 "%7 =   OpTypeFloat 32\n"
174                 "%8 =   OpTypeVector %7 4\n"
175                 "%9 =   OpTypePointer Output %8\n"
176                 "%10 =  OpVariable %9 Output\n"
177                 "%11 =  OpConstant %7 1065353216\n"
178                 "%12 =  OpConstant %7 0\n"
179                 "%13 =  OpConstantComposite %8 %11 %12 %11 %11\n"
180                 "%4 =   OpFunction %2 None %3\n"
181                 "%5 =   OpLabel\n"
182                 "               OpStore %10 %13\n"
183                 "               OpBranch %6\n"
184                 "%6 =   OpLabel\n"
185                 "               OpReturn\n"
186                 "               OpFunctionEnd\n";
187 }
188
189 void createTriangleProgs (SourceCollections& dst)
190 {
191         dst.glslSources.add("vert") << glu::VertexSource(
192                 "#version 300 es\n"
193                 "layout(location = 0) in highp vec4 a_position;\n"
194                 "void main (void) { gl_Position = a_position; }\n");
195         dst.glslSources.add("frag") << glu::FragmentSource(
196                 "#version 300 es\n"
197                 "layout(location = 0) out lowp vec4 o_color;\n"
198                 "void main (void) { o_color = vec4(1.0, 0.0, 1.0, 1.0); }\n");
199 }
200
201 tcu::TestStatus renderTriangleTest (Context& context)
202 {
203         const VkDevice                                                  vkDevice                                = context.getDevice();
204         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
205         const VkQueue                                                   queue                                   = context.getUniversalQueue();
206         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
207         SimpleAllocator                                                 memAlloc                                (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
208         const tcu::IVec2                                                renderSize                              (256, 256);
209
210         const tcu::Vec4                                                 vertices[]                              =
211         {
212                 tcu::Vec4(-0.5f, -0.5f, 0.0f, 1.0f),
213                 tcu::Vec4(+0.5f, -0.5f, 0.0f, 1.0f),
214                 tcu::Vec4( 0.0f, +0.5f, 0.0f, 1.0f)
215         };
216
217         const VkBufferCreateInfo                                vertexBufferParams              =
218         {
219                 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,   // sType
220                 DE_NULL,                                                                // pNext
221                 0u,                                                                             // flags
222                 (VkDeviceSize)sizeof(vertices),                 // size
223                 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,              // usage
224                 VK_SHARING_MODE_EXCLUSIVE,                              // sharingMode
225                 1u,                                                                             // queueFamilyIndexCount
226                 &queueFamilyIndex,                                              // pQueueFamilyIndices
227         };
228         const Unique<VkBuffer>                                  vertexBuffer                    (createBuffer(vk, vkDevice, &vertexBufferParams));
229         const UniquePtr<Allocation>                             vertexBufferMemory              (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible));
230
231         VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferMemory->getMemory(), vertexBufferMemory->getOffset()));
232
233         const VkDeviceSize                                              imageSizeBytes                  = (VkDeviceSize)(sizeof(deUint32)*renderSize.x()*renderSize.y());
234         const VkBufferCreateInfo                                readImageBufferParams   =
235         {
236                 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // sType
237                 DE_NULL,                                                                        // pNext
238                 (VkBufferCreateFlags)0u,                                        // flags
239                 imageSizeBytes,                                                         // size
240                 VK_BUFFER_USAGE_TRANSFER_DST_BIT,                       // usage
241                 VK_SHARING_MODE_EXCLUSIVE,                                      // sharingMode
242                 1u,                                                                                     // queueFamilyIndexCount
243                 &queueFamilyIndex,                                                      // pQueueFamilyIndices
244         };
245         const Unique<VkBuffer>                                  readImageBuffer                 (createBuffer(vk, vkDevice, &readImageBufferParams));
246         const UniquePtr<Allocation>                             readImageBufferMemory   (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *readImageBuffer), MemoryRequirement::HostVisible));
247
248         VK_CHECK(vk.bindBufferMemory(vkDevice, *readImageBuffer, readImageBufferMemory->getMemory(), readImageBufferMemory->getOffset()));
249
250         const VkImageCreateInfo                                 imageParams                             =
251         {
252                 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                                    // sType
253                 DE_NULL,                                                                                                                                // pNext
254                 0u,                                                                                                                                             // flags
255                 VK_IMAGE_TYPE_2D,                                                                                                               // imageType
256                 VK_FORMAT_R8G8B8A8_UNORM,                                                                                               // format
257                 { renderSize.x(), renderSize.y(), 1 },                                                                  // extent
258                 1u,                                                                                                                                             // mipLevels
259                 1u,                                                                                                                                             // arraySize
260                 VK_SAMPLE_COUNT_1_BIT,                                                                                                  // samples
261                 VK_IMAGE_TILING_OPTIMAL,                                                                                                // tiling
262                 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT,    // usage
263                 VK_SHARING_MODE_EXCLUSIVE,                                                                                              // sharingMode
264                 1u,                                                                                                                                             // queueFamilyIndexCount
265                 &queueFamilyIndex,                                                                                                              // pQueueFamilyIndices
266                 VK_IMAGE_LAYOUT_UNDEFINED,                                                                                              // initialLayout
267         };
268
269         const Unique<VkImage>                                   image                                   (createImage(vk, vkDevice, &imageParams));
270         const UniquePtr<Allocation>                             imageMemory                             (memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any));
271
272         VK_CHECK(vk.bindImageMemory(vkDevice, *image, imageMemory->getMemory(), imageMemory->getOffset()));
273
274         const VkAttachmentDescription                   colorAttDesc                    =
275         {
276                 0u,                                                                                             // flags
277                 VK_FORMAT_R8G8B8A8_UNORM,                                               // format
278                 VK_SAMPLE_COUNT_1_BIT,                                                  // samples
279                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                    // loadOp
280                 VK_ATTACHMENT_STORE_OP_STORE,                                   // storeOp
281                 VK_ATTACHMENT_LOAD_OP_DONT_CARE,                                // stencilLoadOp
282                 VK_ATTACHMENT_STORE_OP_DONT_CARE,                               // stencilStoreOp
283                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // initialLayout
284                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // finalLayout
285         };
286         const VkAttachmentReference                             colorAttRef                             =
287         {
288                 0u,                                                                                             // attachment
289                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // layout
290         };
291         const VkSubpassDescription                              subpassDesc                             =
292         {
293                 (VkSubpassDescriptionFlags)0u,                                  // flags
294                 VK_PIPELINE_BIND_POINT_GRAPHICS,                                // pipelineBindPoint
295                 0u,                                                                                             // inputAttachmentCount
296                 DE_NULL,                                                                                // pInputAttachments
297                 1u,                                                                                             // colorAttachmentCount
298                 &colorAttRef,                                                                   // pColorAttachments
299                 DE_NULL,                                                                                // pResolveAttachments
300                 DE_NULL,                                                                                // depthStencilAttachment
301                 0u,                                                                                             // preserveAttachmentCount
302                 DE_NULL,                                                                                // pPreserveAttachments
303         };
304         const VkRenderPassCreateInfo                    renderPassParams                =
305         {
306                 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,              // sType
307                 DE_NULL,                                                                                // pNext
308                 0u,                                                                                             // flags
309                 1u,                                                                                             // attachmentCount
310                 &colorAttDesc,                                                                  // pAttachments
311                 1u,                                                                                             // subpassCount
312                 &subpassDesc,                                                                   // pSubpasses
313                 0u,                                                                                             // dependencyCount
314                 DE_NULL,                                                                                // pDependencies
315         };
316         const Unique<VkRenderPass>                              renderPass                              (createRenderPass(vk, vkDevice, &renderPassParams));
317
318         const VkImageViewCreateInfo                             colorAttViewParams              =
319         {
320                 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,               // sType
321                 DE_NULL,                                                                                // pNext
322                 0u,                                                                                             // flags
323                 *image,                                                                                 // image
324                 VK_IMAGE_VIEW_TYPE_2D,                                                  // viewType
325                 VK_FORMAT_R8G8B8A8_UNORM,                                               // format
326                 {
327                         VK_COMPONENT_SWIZZLE_R,
328                         VK_COMPONENT_SWIZZLE_G,
329                         VK_COMPONENT_SWIZZLE_B,
330                         VK_COMPONENT_SWIZZLE_A
331                 },                                                                                              // components
332                 {
333                         VK_IMAGE_ASPECT_COLOR_BIT,                                              // aspectMask
334                         0u,                                                                                             // baseMipLevel
335                         1u,                                                                                             // levelCount
336                         0u,                                                                                             // baseArrayLayer
337                         1u,                                                                                             // layerCount
338                 },                                                                                              // subresourceRange
339         };
340         const Unique<VkImageView>                               colorAttView                    (createImageView(vk, vkDevice, &colorAttViewParams));
341
342         // Pipeline layout
343         const VkPipelineLayoutCreateInfo                pipelineLayoutParams    =
344         {
345                 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,                  // sType
346                 DE_NULL,                                                                                                // pNext
347                 (vk::VkPipelineLayoutCreateFlags)0,
348                 0u,                                                                                                             // setLayoutCount
349                 DE_NULL,                                                                                                // pSetLayouts
350                 0u,                                                                                                             // pushConstantRangeCount
351                 DE_NULL,                                                                                                // pPushConstantRanges
352         };
353         const Unique<VkPipelineLayout>                  pipelineLayout                  (createPipelineLayout(vk, vkDevice, &pipelineLayoutParams));
354
355         // Shaders
356         const Unique<VkShaderModule>                    vertShaderModule                (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("vert"), 0));
357         const Unique<VkShaderModule>                    fragShaderModule                (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("frag"), 0));
358
359         // Pipeline
360         const VkSpecializationInfo                              emptyShaderSpecParams   =
361         {
362                 0u,                                                                                                             // mapEntryCount
363                 DE_NULL,                                                                                                // pMap
364                 0,                                                                                                              // dataSize
365                 DE_NULL,                                                                                                // pData
366         };
367         const VkPipelineShaderStageCreateInfo   shaderStageParams[]     =
368         {
369                 {
370                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // sType
371                         DE_NULL,                                                                                                // pNext
372                         0u,                                                                                                             // flags
373                         VK_SHADER_STAGE_VERTEX_BIT,                                                             // stage
374                         *vertShaderModule,                                                                              // module
375                         "main",                                                                                                 // pName
376                         &emptyShaderSpecParams,                                                                 // pSpecializationInfo
377                 },
378                 {
379                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // sType
380                         DE_NULL,                                                                                                // pNext
381                         0u,                                                                                                             // flags
382                         VK_SHADER_STAGE_FRAGMENT_BIT,                                                   // stage
383                         *fragShaderModule,                                                                              // module
384                         "main",                                                                                                 // pName
385                         &emptyShaderSpecParams,                                                                 // pSpecializationInfo
386                 }
387         };
388         const VkPipelineDepthStencilStateCreateInfo     depthStencilParams              =
389         {
390                 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,     // sType
391                 DE_NULL,                                                                                                        // pNext
392                 0u,                                                                                                                     // flags
393                 DE_FALSE,                                                                                                       // depthTestEnable
394                 DE_FALSE,                                                                                                       // depthWriteEnable
395                 VK_COMPARE_OP_ALWAYS,                                                                           // depthCompareOp
396                 DE_FALSE,                                                                                                       // depthBoundsTestEnable
397                 DE_FALSE,                                                                                                       // stencilTestEnable
398                 {
399                         VK_STENCIL_OP_KEEP,                                                                                     // failOp
400                         VK_STENCIL_OP_KEEP,                                                                                     // passOp
401                         VK_STENCIL_OP_KEEP,                                                                                     // depthFailOp
402                         VK_COMPARE_OP_ALWAYS,                                                                           // compareOp
403                         0u,                                                                                                                     // compareMask
404                         0u,                                                                                                                     // writeMask
405                         0u,                                                                                                                     // reference
406                 },                                                                                                                      // front
407                 {
408                         VK_STENCIL_OP_KEEP,                                                                                     // failOp
409                         VK_STENCIL_OP_KEEP,                                                                                     // passOp
410                         VK_STENCIL_OP_KEEP,                                                                                     // depthFailOp
411                         VK_COMPARE_OP_ALWAYS,                                                                           // compareOp
412                         0u,                                                                                                                     // compareMask
413                         0u,                                                                                                                     // writeMask
414                         0u,                                                                                                                     // reference
415                 },                                                                                                                      // back;
416                 -1.0f,                                                                                                          //      float                           minDepthBounds;
417                 +1.0f,                                                                                                          //      float                           maxDepthBounds;
418         };
419         const VkViewport                                                viewport0                               =
420         {
421                 0.0f,                                                                                                           // x
422                 0.0f,                                                                                                           // y
423                 (float)renderSize.x(),                                                                          // width
424                 (float)renderSize.y(),                                                                          // height
425                 0.0f,                                                                                                           // minDepth
426                 1.0f,                                                                                                           // maxDepth
427         };
428         const VkRect2D                                                  scissor0                                =
429         {
430                 {
431                         0u,                                                                                                                     // x
432                         0u,                                                                                                                     // y
433                 },                                                                                                                      // offset
434                 {
435                         renderSize.x(),                                                                                         // width
436                         renderSize.y(),                                                                                         // height
437                 },                                                                                                                      // extent;
438         };
439         const VkPipelineViewportStateCreateInfo         viewportParams                  =
440         {
441                 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,          // sType
442                 DE_NULL,                                                                                                        // pNext
443                 0u,                                                                                                                     // flags
444                 1u,                                                                                                                     // viewportCount
445                 &viewport0,                                                                                                     // pViewports
446                 1u,                                                                                                                     // scissorCount
447                 &scissor0                                                                                                       // pScissors
448         };
449         const VkSampleMask                                                      sampleMask                              = ~0u;
450         const VkPipelineMultisampleStateCreateInfo      multisampleParams               =
451         {
452                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // sType
453                 DE_NULL,                                                                                                        // pNext
454                 0u,                                                                                                                     // flags
455                 VK_SAMPLE_COUNT_1_BIT,                                                                          // rasterizationSamples
456                 VK_FALSE,                                                                                                       // sampleShadingEnable
457                 0.0f,                                                                                                           // minSampleShading
458                 &sampleMask,                                                                                            // sampleMask
459                 VK_FALSE,                                                                                                       // alphaToCoverageEnable
460                 VK_FALSE,                                                                                                       // alphaToOneEnable
461         };
462         const VkPipelineRasterizationStateCreateInfo    rasterParams            =
463         {
464                 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,     // sType
465                 DE_NULL,                                                                                                        // pNext
466                 0u,                                                                                                                     // flags
467                 VK_TRUE,                                                                                                        // depthClampEnable
468                 VK_FALSE,                                                                                                       // rasterizerDiscardEnable
469                 VK_POLYGON_MODE_FILL,                                                                           // polygonMode
470                 VK_CULL_MODE_NONE,                                                                                      // cullMode
471                 VK_FRONT_FACE_COUNTER_CLOCKWISE,                                                        // frontFace
472                 VK_FALSE,                                                                                                       // depthBiasEnable
473                 0.0f,                                                                                                           // depthBiasConstantFactor
474                 0.0f,                                                                                                           // depthBiasClamp
475                 0.0f,                                                                                                           // depthBiasSlopeFactor
476                 1.0f,                                                                                                           // lineWidth
477         };
478         const VkPipelineInputAssemblyStateCreateInfo    inputAssemblyParams     =
479         {
480                 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,    // sType
481                 DE_NULL,                                                                                                                // pNext
482                 0u,                                                                                                                             // flags
483                 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,                                                    // topology
484                 DE_FALSE,                                                                                                               // primitiveRestartEnable
485         };
486         const VkVertexInputBindingDescription           vertexBinding0                  =
487         {
488                 0u,                                                                                                             // binding
489                 (deUint32)sizeof(tcu::Vec4),                                                    // stride
490                 VK_VERTEX_INPUT_RATE_VERTEX,                                                    // inputRate
491         };
492         const VkVertexInputAttributeDescription         vertexAttrib0                   =
493         {
494                 0u,                                                                                                             // location
495                 0u,                                                                                                             // binding
496                 VK_FORMAT_R32G32B32A32_SFLOAT,                                                  // format
497                 0u,                                                                                                             // offset
498         };
499         const VkPipelineVertexInputStateCreateInfo      vertexInputStateParams  =
500         {
501                 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,      // sType
502                 DE_NULL,                                                                                                        // pNext
503                 0u,                                                                                                                     // flags
504                 1u,                                                                                                                     // vertexBindingDescriptionCount
505                 &vertexBinding0,                                                                                        // pVertexBindingDescriptions
506                 1u,                                                                                                                     // vertexAttributeDescriptionCount
507                 &vertexAttrib0,                                                                                         // pVertexAttributeDescriptions
508         };
509         const VkPipelineColorBlendAttachmentState       attBlendParams                  =
510         {
511                 VK_FALSE,                                                                                                       // blendEnable
512                 VK_BLEND_FACTOR_ONE,                                                                            // srcColorBlendFactor
513                 VK_BLEND_FACTOR_ZERO,                                                                           // dstColorBlendFactor
514                 VK_BLEND_OP_ADD,                                                                                        // colorBlendOp
515                 VK_BLEND_FACTOR_ONE,                                                                            // srcAlphaBlendFactor
516                 VK_BLEND_FACTOR_ZERO,                                                                           // dstAlphaBlendFactor
517                 VK_BLEND_OP_ADD,                                                                                        // alphaBlendOp
518                 (VK_COLOR_COMPONENT_R_BIT|
519                  VK_COLOR_COMPONENT_G_BIT|
520                  VK_COLOR_COMPONENT_B_BIT|
521                  VK_COLOR_COMPONENT_A_BIT),                                                                     // colorWriteMask
522         };
523         const VkPipelineColorBlendStateCreateInfo       blendParams                             =
524         {
525                 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,       // sType
526                 DE_NULL,                                                                                                        // pNext
527                 0u,                                                                                                                     // flags
528                 DE_FALSE,                                                                                                       // logicOpEnable
529                 VK_LOGIC_OP_COPY,                                                                                       // logicOp
530                 1u,                                                                                                                     // attachmentCount
531                 &attBlendParams,                                                                                        // pAttachments
532                 { 0.0f, 0.0f, 0.0f, 0.0f },                                                                     // blendConstants[4]
533         };
534         const VkPipelineDynamicStateCreateInfo  dynamicStateInfo                =
535         {
536                 VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,   // sType
537                 DE_NULL,                                                                                                // pNext
538                 0u,                                                                                                             // flags
539                 0u,                                                                                                             // dynamicStateCount
540                 DE_NULL                                                                                                 // pDynamicStates
541         };
542         const VkGraphicsPipelineCreateInfo              pipelineParams                  =
543         {
544                 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,                // sType
545                 DE_NULL,                                                                                                // pNext
546                 0u,                                                                                                             // flags
547                 (deUint32)DE_LENGTH_OF_ARRAY(shaderStageParams),                // stageCount
548                 shaderStageParams,                                                                              // pStages
549                 &vertexInputStateParams,                                                                // pVertexInputState
550                 &inputAssemblyParams,                                                                   // pInputAssemblyState
551                 DE_NULL,                                                                                                // pTessellationState
552                 &viewportParams,                                                                                // pViewportState
553                 &rasterParams,                                                                                  // pRasterizationState
554                 &multisampleParams,                                                                             // pMultisampleState
555                 &depthStencilParams,                                                                    // pDepthStencilState
556                 &blendParams,                                                                                   // pColorBlendState
557                 &dynamicStateInfo,                                                                              // pDynamicState
558                 *pipelineLayout,                                                                                // layout
559                 *renderPass,                                                                                    // renderPass
560                 0u,                                                                                                             // subpass
561                 DE_NULL,                                                                                                // basePipelineHandle
562                 0u,                                                                                                             // basePipelineIndex
563         };
564
565         const Unique<VkPipeline>                                pipeline                                (createGraphicsPipeline(vk, vkDevice, DE_NULL, &pipelineParams));
566
567         // Framebuffer
568         const VkFramebufferCreateInfo                   framebufferParams               =
569         {
570                 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,                              // sType
571                 DE_NULL,                                                                                                // pNext
572                 0u,                                                                                                             // flags
573                 *renderPass,                                                                                    // renderPass
574                 1u,                                                                                                             // attachmentCount
575                 &*colorAttView,                                                                                 // pAttachments
576                 (deUint32)renderSize.x(),                                                               // width
577                 (deUint32)renderSize.y(),                                                               // height
578                 1u,                                                                                                             // layers
579         };
580         const Unique<VkFramebuffer>                             framebuffer                             (createFramebuffer(vk, vkDevice, &framebufferParams));
581
582         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
583         {
584                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType
585                 DE_NULL,                                                                                                        // pNext
586                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags
587                 queueFamilyIndex,                                                                                       // queueFamilyIndex
588         };
589         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
590
591         // Command buffer
592         const VkCommandBufferAllocateInfo               cmdBufParams                    =
593         {
594                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                 // sType
595                 DE_NULL,                                                                                                // pNext
596                 *cmdPool,                                                                                               // pool
597                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                // level
598                 1u,                                                                                                             // bufferCount
599         };
600         const Unique<VkCommandBuffer>                   cmdBuf                                  (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
601
602         const VkCommandBufferBeginInfo                  cmdBufBeginParams               =
603         {
604                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // sType
605                 DE_NULL,                                                                                                // pNext
606                 0u,                                                                                                             // flags
607                 DE_NULL,                                                                                                // renderPass
608                 0u,                                                                                                             // subpass
609                 DE_NULL,                                                                                                // framebuffer
610                 VK_FALSE,                                                                                               // occlusionQueryEnable
611                 (VkQueryControlFlags)0u,                                                                // queryFlags
612                 (VkQueryPipelineStatisticFlags)0u,                                              // pipelineStatistics
613         };
614
615         // Record commands
616         VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginParams));
617
618         {
619                 const VkMemoryBarrier           vertFlushBarrier        =
620                 {
621                         VK_STRUCTURE_TYPE_MEMORY_BARRIER,                       // sType
622                         DE_NULL,                                                                        // pNext
623                         VK_ACCESS_HOST_WRITE_BIT,                                       // srcAccessMask
624                         VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT,            // dstAccessMask
625                 };
626                 const VkImageMemoryBarrier      colorAttBarrier         =
627                 {
628                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // sType
629                         DE_NULL,                                                                        // pNext
630                         0u,                                                                                     // srcAccessMask
631                         (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT|
632                          VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT),         // dstAccessMask
633                         VK_IMAGE_LAYOUT_UNDEFINED,                                      // oldLayout
634                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // newLayout
635                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
636                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
637                         *image,                                                                         // image
638                         {
639                                 VK_IMAGE_ASPECT_COLOR_BIT,                                      // aspectMask
640                                 0u,                                                                                     // baseMipLevel
641                                 1u,                                                                                     // levelCount
642                                 0u,                                                                                     // baseArrayLayer
643                                 1u,                                                                                     // layerCount
644                         }                                                                                       // subresourceRange
645                 };
646                 const void*                             barriers[]                              = { &vertFlushBarrier, &colorAttBarrier };
647                 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, DE_FALSE, (deUint32)DE_LENGTH_OF_ARRAY(barriers), barriers);
648         }
649
650         {
651                 const VkClearValue                      clearValue              = makeClearValueColorF32(0.125f, 0.25f, 0.75f, 1.0f);
652                 const VkRenderPassBeginInfo     passBeginParams =
653                 {
654                         VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,                       // sType
655                         DE_NULL,                                                                                        // pNext
656                         *renderPass,                                                                            // renderPass
657                         *framebuffer,                                                                           // framebuffer
658                         { { 0, 0 }, { renderSize.x(), renderSize.y() } },       // renderArea
659                         1u,                                                                                                     // clearValueCount
660                         &clearValue,                                                                            // pClearValues
661                 };
662                 vk.cmdBeginRenderPass(*cmdBuf, &passBeginParams, VK_SUBPASS_CONTENTS_INLINE);
663         }
664
665         vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
666         {
667                 const VkDeviceSize bindingOffset = 0;
668                 vk.cmdBindVertexBuffers(*cmdBuf, 0u, 1u, &vertexBuffer.get(), &bindingOffset);
669         }
670         vk.cmdDraw(*cmdBuf, 3u, 1u, 0u, 0u);
671         vk.cmdEndRenderPass(*cmdBuf);
672
673         {
674                 const VkImageMemoryBarrier      renderFinishBarrier     =
675                 {
676                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // sType
677                         DE_NULL,                                                                        // pNext
678                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,           // outputMask
679                         VK_ACCESS_TRANSFER_READ_BIT,                            // inputMask
680                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // oldLayout
681                         VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,           // newLayout
682                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
683                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
684                         *image,                                                                         // image
685                         {
686                                 VK_IMAGE_ASPECT_COLOR_BIT,                                      // aspectMask
687                                 0u,                                                                                     // baseMipLevel
688                                 1u,                                                                                     // mipLevels
689                                 0u,                                                                                     // baseArraySlice
690                                 1u,                                                                                     // arraySize
691                         }                                                                                       // subresourceRange
692                 };
693                 const void*                             barriers[]                              = { &renderFinishBarrier };
694                 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, DE_FALSE, (deUint32)DE_LENGTH_OF_ARRAY(barriers), barriers);
695         }
696
697         {
698                 const VkBufferImageCopy copyParams      =
699                 {
700                         (VkDeviceSize)0u,                                               // bufferOffset
701                         (deUint32)renderSize.x(),                               // bufferRowLength
702                         (deUint32)renderSize.y(),                               // bufferImageHeight
703                         {
704                                 VK_IMAGE_ASPECT_COLOR_BIT,                              // aspectMask
705                                 0u,                                                                             // mipLevel
706                                 0u,                                                                             // baseArrayLayer
707                                 1u,                                                                             // layerCount
708                         },                                                                              // imageSubresource
709                         { 0u, 0u, 0u },                                                 // imageOffset
710                         { renderSize.x(), renderSize.y(), 1u }  // imageExtent
711                 };
712                 vk.cmdCopyImageToBuffer(*cmdBuf, *image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *readImageBuffer, 1u, &copyParams);
713         }
714
715         {
716                 const VkBufferMemoryBarrier     copyFinishBarrier       =
717                 {
718                         VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // sType
719                         DE_NULL,                                                                        // pNext
720                         VK_ACCESS_TRANSFER_WRITE_BIT,                           // srcAccessMask
721                         VK_ACCESS_HOST_READ_BIT,                                        // dstAccessMask
722                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
723                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
724                         *readImageBuffer,                                                       // buffer
725                         0u,                                                                                     // offset
726                         imageSizeBytes                                                          // size
727                 };
728                 const void*                             barriers[]                              = { &copyFinishBarrier };
729                 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, DE_FALSE, (deUint32)DE_LENGTH_OF_ARRAY(barriers), barriers);
730         }
731
732         VK_CHECK(vk.endCommandBuffer(*cmdBuf));
733
734         // Upload vertex data
735         {
736                 const VkMappedMemoryRange       range                   =
737                 {
738                         VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,  // sType
739                         DE_NULL,                                                                // pNext
740                         vertexBufferMemory->getMemory(),                // memory
741                         0,                                                                              // offset
742                         (VkDeviceSize)sizeof(vertices),                 // size
743                 };
744                 void*                                           vertexBufPtr    = vertexBufferMemory->getHostPtr();
745
746                 deMemcpy(vertexBufPtr, &vertices[0], sizeof(vertices));
747                 VK_CHECK(vk.flushMappedMemoryRanges(vkDevice, 1u, &range));
748         }
749
750         // Submit & wait for completion
751         {
752                 const VkFenceCreateInfo fenceParams     =
753                 {
754                         VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,    // sType
755                         DE_NULL,                                                                // pNext
756                         0u,                                                                             // flags
757                 };
758                 const VkSubmitInfo              submitInfo      =
759                 {
760                         VK_STRUCTURE_TYPE_SUBMIT_INFO,                  // sType
761                         DE_NULL,                                                                // pNext
762                         0u,                                                                             // waitSemaphoreCount
763                         DE_NULL,                                                                // pWaitSemaphores
764                         1u,                                                                             // commandBufferCount
765                         &cmdBuf.get(),                                                  // pCommandBuffers
766                         0u,                                                                             // signalSemaphoreCount
767                         DE_NULL,                                                                // pSignalSemaphores
768                 };
769                 const Unique<VkFence>   fence           (createFence(vk, vkDevice, &fenceParams));
770
771                 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
772                 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), DE_TRUE, ~0ull));
773         }
774
775         // Log image
776         {
777                 const VkMappedMemoryRange       range           =
778                 {
779                         VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,  // sType
780                         DE_NULL,                                                                // pNext
781                         readImageBufferMemory->getMemory(),             // memory
782                         0,                                                                              // offset
783                         imageSizeBytes,                                                 // size
784                 };
785                 void*                                           imagePtr        = readImageBufferMemory->getHostPtr();
786
787                 VK_CHECK(vk.invalidateMappedMemoryRanges(vkDevice, 1u, &range));
788                 context.getTestContext().getLog() << TestLog::Image("Result", "Result", tcu::ConstPixelBufferAccess(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), renderSize.x(), renderSize.y(), 1, imagePtr));
789         }
790
791         return tcu::TestStatus::pass("Rendering succeeded");
792 }
793
794 } // anonymous
795
796 tcu::TestCaseGroup* createSmokeTests (tcu::TestContext& testCtx)
797 {
798         de::MovePtr<tcu::TestCaseGroup> smokeTests      (new tcu::TestCaseGroup(testCtx, "smoke", "Smoke Tests"));
799
800         addFunctionCase                         (smokeTests.get(), "create_sampler",    "",     createSamplerTest);
801         addFunctionCaseWithPrograms     (smokeTests.get(), "create_shader",             "", createShaderProgs,          createShaderModuleTest);
802         addFunctionCaseWithPrograms     (smokeTests.get(), "triangle",                  "", createTriangleProgs,        renderTriangleTest);
803         addFunctionCaseWithPrograms     (smokeTests.get(), "asm_triangle",              "", createTriangleAsmProgs,     renderTriangleTest);
804
805         return smokeTests.release();
806 }
807
808 } // api
809 } // vkt