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