Merge branch 'jekstrand_renderpass_transfer_bit_fix' 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 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_NEAREST,                         // 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                         VK_FALSE,                                                                       // anisotropyEnable
87                         1.0f,                                                                           // maxAnisotropy
88                         DE_FALSE,                                                                       // compareEnable
89                         VK_COMPARE_OP_ALWAYS,                                           // compareOp
90                         0.0f,                                                                           // minLod
91                         0.0f,                                                                           // maxLod
92                         VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,        // borderColor
93                         VK_FALSE,                                                                       // unnormalizedCoords
94                 };
95
96                 Move<VkSampler>                 tmpSampler      = createSampler(vk, vkDevice, &samplerInfo);
97                 Move<VkSampler>                 tmp2Sampler;
98
99                 tmp2Sampler = tmpSampler;
100
101                 const Unique<VkSampler> sampler         (tmp2Sampler);
102         }
103
104         return tcu::TestStatus::pass("Creating sampler succeeded");
105 }
106
107 void createShaderProgs (SourceCollections& dst)
108 {
109         dst.glslSources.add("test") << glu::VertexSource(
110                 "#version 300 es\n"
111                 "in highp vec4 a_position;\n"
112                 "void main (void) { gl_Position = a_position; }\n");
113 }
114
115 tcu::TestStatus createShaderModuleTest (Context& context)
116 {
117         const VkDevice                                  vkDevice        = context.getDevice();
118         const DeviceInterface&                  vk                      = context.getDeviceInterface();
119         const Unique<VkShaderModule>    shader          (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("test"), 0));
120
121         return tcu::TestStatus::pass("Creating shader module succeeded");
122 }
123
124 void createTriangleAsmProgs (SourceCollections& dst)
125 {
126         dst.spirvAsmSources.add("vert") <<
127                 "                OpCapability Shader\n"
128                 "%1 =    OpExtInstImport \"GLSL.std.450\"\n"
129                 "                OpMemoryModel Logical GLSL450\n"
130                 "                OpEntryPoint Vertex %4 \"main\" %10 %12 %16 %17\n"
131                 "                OpSource ESSL 300\n"
132                 "                OpName %4 \"main\"\n"
133                 "                OpName %10 \"gl_Position\"\n"
134                 "                OpName %12 \"a_position\"\n"
135                 "                OpName %16 \"gl_VertexIndex\"\n"
136                 "                OpName %17 \"gl_InstanceIndex\"\n"
137                 "                OpDecorate %10 BuiltIn Position\n"
138                 "                OpDecorate %12 Location 0\n"
139                 "                OpDecorate %16 BuiltIn VertexIndex\n"
140                 "                OpDecorate %17 BuiltIn InstanceIndex\n"
141                 "%2 =    OpTypeVoid\n"
142                 "%3 =    OpTypeFunction %2\n"
143                 "%7 =    OpTypeFloat 32\n"
144                 "%8 =    OpTypeVector %7 4\n"
145                 "%9 =    OpTypePointer Output %8\n"
146                 "%10 =   OpVariable %9 Output\n"
147                 "%11 =   OpTypePointer Input %8\n"
148                 "%12 =   OpVariable %11 Input\n"
149                 "%14 =   OpTypeInt 32 1\n"
150                 "%15 =   OpTypePointer Input %14\n"
151                 "%16 =   OpVariable %15 Input\n"
152                 "%17 =   OpVariable %15 Input\n"
153                 "%4 =    OpFunction %2 None %3\n"
154                 "%5 =    OpLabel\n"
155                 "%13 =   OpLoad %8 %12\n"
156                 "                OpStore %10 %13\n"
157                 "                OpBranch %6\n"
158                 "%6 =    OpLabel\n"
159                 "                OpReturn\n"
160                 "                OpFunctionEnd\n";
161         dst.spirvAsmSources.add("frag") <<
162                 "               OpCapability Shader\n"
163                 "%1 =   OpExtInstImport \"GLSL.std.450\"\n"
164                 "               OpMemoryModel Logical GLSL450\n"
165                 "               OpEntryPoint Fragment %4 \"main\" %10\n"
166                 "               OpExecutionMode %4 OriginLowerLeft\n"
167                 "               OpSource ESSL 300\n"
168                 "               OpName %4 \"main\"\n"
169                 "               OpName %10 \"o_color\"\n"
170                 "               OpDecorate %10 RelaxedPrecision\n"
171                 "               OpDecorate %10 Location 0\n"
172                 "%2 =   OpTypeVoid\n"
173                 "%3 =   OpTypeFunction %2\n"
174                 "%7 =   OpTypeFloat 32\n"
175                 "%8 =   OpTypeVector %7 4\n"
176                 "%9 =   OpTypePointer Output %8\n"
177                 "%10 =  OpVariable %9 Output\n"
178                 "%11 =  OpConstant %7 1065353216\n"
179                 "%12 =  OpConstant %7 0\n"
180                 "%13 =  OpConstantComposite %8 %11 %12 %11 %11\n"
181                 "%4 =   OpFunction %2 None %3\n"
182                 "%5 =   OpLabel\n"
183                 "               OpStore %10 %13\n"
184                 "               OpBranch %6\n"
185                 "%6 =   OpLabel\n"
186                 "               OpReturn\n"
187                 "               OpFunctionEnd\n";
188 }
189
190 void createTriangleProgs (SourceCollections& dst)
191 {
192         dst.glslSources.add("vert") << glu::VertexSource(
193                 "#version 300 es\n"
194                 "layout(location = 0) in highp vec4 a_position;\n"
195                 "void main (void) { gl_Position = a_position; }\n");
196         dst.glslSources.add("frag") << glu::FragmentSource(
197                 "#version 300 es\n"
198                 "layout(location = 0) out lowp vec4 o_color;\n"
199                 "void main (void) { o_color = vec4(1.0, 0.0, 1.0, 1.0); }\n");
200 }
201
202 tcu::TestStatus renderTriangleTest (Context& context)
203 {
204         const VkDevice                                                  vkDevice                                = context.getDevice();
205         const DeviceInterface&                                  vk                                              = context.getDeviceInterface();
206         const VkQueue                                                   queue                                   = context.getUniversalQueue();
207         const deUint32                                                  queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
208         SimpleAllocator                                                 memAlloc                                (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
209         const tcu::IVec2                                                renderSize                              (256, 256);
210
211         const tcu::Vec4                                                 vertices[]                              =
212         {
213                 tcu::Vec4(-0.5f, -0.5f, 0.0f, 1.0f),
214                 tcu::Vec4(+0.5f, -0.5f, 0.0f, 1.0f),
215                 tcu::Vec4( 0.0f, +0.5f, 0.0f, 1.0f)
216         };
217
218         const VkBufferCreateInfo                                vertexBufferParams              =
219         {
220                 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,   // sType
221                 DE_NULL,                                                                // pNext
222                 0u,                                                                             // flags
223                 (VkDeviceSize)sizeof(vertices),                 // size
224                 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,              // usage
225                 VK_SHARING_MODE_EXCLUSIVE,                              // sharingMode
226                 1u,                                                                             // queueFamilyIndexCount
227                 &queueFamilyIndex,                                              // pQueueFamilyIndices
228         };
229         const Unique<VkBuffer>                                  vertexBuffer                    (createBuffer(vk, vkDevice, &vertexBufferParams));
230         const UniquePtr<Allocation>                             vertexBufferMemory              (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible));
231
232         VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferMemory->getMemory(), vertexBufferMemory->getOffset()));
233
234         const VkDeviceSize                                              imageSizeBytes                  = (VkDeviceSize)(sizeof(deUint32)*renderSize.x()*renderSize.y());
235         const VkBufferCreateInfo                                readImageBufferParams   =
236         {
237                 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // sType
238                 DE_NULL,                                                                        // pNext
239                 (VkBufferCreateFlags)0u,                                        // flags
240                 imageSizeBytes,                                                         // size
241                 VK_BUFFER_USAGE_TRANSFER_DST_BIT,                       // usage
242                 VK_SHARING_MODE_EXCLUSIVE,                                      // sharingMode
243                 1u,                                                                                     // queueFamilyIndexCount
244                 &queueFamilyIndex,                                                      // pQueueFamilyIndices
245         };
246         const Unique<VkBuffer>                                  readImageBuffer                 (createBuffer(vk, vkDevice, &readImageBufferParams));
247         const UniquePtr<Allocation>                             readImageBufferMemory   (memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *readImageBuffer), MemoryRequirement::HostVisible));
248
249         VK_CHECK(vk.bindBufferMemory(vkDevice, *readImageBuffer, readImageBufferMemory->getMemory(), readImageBufferMemory->getOffset()));
250
251         const VkImageCreateInfo                                 imageParams                             =
252         {
253                 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                                    // sType
254                 DE_NULL,                                                                                                                                // pNext
255                 0u,                                                                                                                                             // flags
256                 VK_IMAGE_TYPE_2D,                                                                                                               // imageType
257                 VK_FORMAT_R8G8B8A8_UNORM,                                                                                               // format
258                 { (deUint32)renderSize.x(), (deUint32)renderSize.y(), 1 },                              // extent
259                 1u,                                                                                                                                             // mipLevels
260                 1u,                                                                                                                                             // arraySize
261                 VK_SAMPLE_COUNT_1_BIT,                                                                                                  // samples
262                 VK_IMAGE_TILING_OPTIMAL,                                                                                                // tiling
263                 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT,    // usage
264                 VK_SHARING_MODE_EXCLUSIVE,                                                                                              // sharingMode
265                 1u,                                                                                                                                             // queueFamilyIndexCount
266                 &queueFamilyIndex,                                                                                                              // pQueueFamilyIndices
267                 VK_IMAGE_LAYOUT_UNDEFINED,                                                                                              // initialLayout
268         };
269
270         const Unique<VkImage>                                   image                                   (createImage(vk, vkDevice, &imageParams));
271         const UniquePtr<Allocation>                             imageMemory                             (memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any));
272
273         VK_CHECK(vk.bindImageMemory(vkDevice, *image, imageMemory->getMemory(), imageMemory->getOffset()));
274
275         const VkAttachmentDescription                   colorAttDesc                    =
276         {
277                 0u,                                                                                             // flags
278                 VK_FORMAT_R8G8B8A8_UNORM,                                               // format
279                 VK_SAMPLE_COUNT_1_BIT,                                                  // samples
280                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                    // loadOp
281                 VK_ATTACHMENT_STORE_OP_STORE,                                   // storeOp
282                 VK_ATTACHMENT_LOAD_OP_DONT_CARE,                                // stencilLoadOp
283                 VK_ATTACHMENT_STORE_OP_DONT_CARE,                               // stencilStoreOp
284                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // initialLayout
285                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // finalLayout
286         };
287         const VkAttachmentReference                             colorAttRef                             =
288         {
289                 0u,                                                                                             // attachment
290                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,               // layout
291         };
292         const VkSubpassDescription                              subpassDesc                             =
293         {
294                 (VkSubpassDescriptionFlags)0u,                                  // flags
295                 VK_PIPELINE_BIND_POINT_GRAPHICS,                                // pipelineBindPoint
296                 0u,                                                                                             // inputAttachmentCount
297                 DE_NULL,                                                                                // pInputAttachments
298                 1u,                                                                                             // colorAttachmentCount
299                 &colorAttRef,                                                                   // pColorAttachments
300                 DE_NULL,                                                                                // pResolveAttachments
301                 DE_NULL,                                                                                // depthStencilAttachment
302                 0u,                                                                                             // preserveAttachmentCount
303                 DE_NULL,                                                                                // pPreserveAttachments
304         };
305         const VkRenderPassCreateInfo                    renderPassParams                =
306         {
307                 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,              // sType
308                 DE_NULL,                                                                                // pNext
309                 0u,                                                                                             // flags
310                 1u,                                                                                             // attachmentCount
311                 &colorAttDesc,                                                                  // pAttachments
312                 1u,                                                                                             // subpassCount
313                 &subpassDesc,                                                                   // pSubpasses
314                 0u,                                                                                             // dependencyCount
315                 DE_NULL,                                                                                // pDependencies
316         };
317         const Unique<VkRenderPass>                              renderPass                              (createRenderPass(vk, vkDevice, &renderPassParams));
318
319         const VkImageViewCreateInfo                             colorAttViewParams              =
320         {
321                 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,               // sType
322                 DE_NULL,                                                                                // pNext
323                 0u,                                                                                             // flags
324                 *image,                                                                                 // image
325                 VK_IMAGE_VIEW_TYPE_2D,                                                  // viewType
326                 VK_FORMAT_R8G8B8A8_UNORM,                                               // format
327                 {
328                         VK_COMPONENT_SWIZZLE_R,
329                         VK_COMPONENT_SWIZZLE_G,
330                         VK_COMPONENT_SWIZZLE_B,
331                         VK_COMPONENT_SWIZZLE_A
332                 },                                                                                              // components
333                 {
334                         VK_IMAGE_ASPECT_COLOR_BIT,                                              // aspectMask
335                         0u,                                                                                             // baseMipLevel
336                         1u,                                                                                             // levelCount
337                         0u,                                                                                             // baseArrayLayer
338                         1u,                                                                                             // layerCount
339                 },                                                                                              // subresourceRange
340         };
341         const Unique<VkImageView>                               colorAttView                    (createImageView(vk, vkDevice, &colorAttViewParams));
342
343         // Pipeline layout
344         const VkPipelineLayoutCreateInfo                pipelineLayoutParams    =
345         {
346                 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,                  // sType
347                 DE_NULL,                                                                                                // pNext
348                 (vk::VkPipelineLayoutCreateFlags)0,
349                 0u,                                                                                                             // setLayoutCount
350                 DE_NULL,                                                                                                // pSetLayouts
351                 0u,                                                                                                             // pushConstantRangeCount
352                 DE_NULL,                                                                                                // pPushConstantRanges
353         };
354         const Unique<VkPipelineLayout>                  pipelineLayout                  (createPipelineLayout(vk, vkDevice, &pipelineLayoutParams));
355
356         // Shaders
357         const Unique<VkShaderModule>                    vertShaderModule                (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("vert"), 0));
358         const Unique<VkShaderModule>                    fragShaderModule                (createShaderModule(vk, vkDevice, context.getBinaryCollection().get("frag"), 0));
359
360         // Pipeline
361         const VkSpecializationInfo                              emptyShaderSpecParams   =
362         {
363                 0u,                                                                                                             // mapEntryCount
364                 DE_NULL,                                                                                                // pMap
365                 0,                                                                                                              // dataSize
366                 DE_NULL,                                                                                                // pData
367         };
368         const VkPipelineShaderStageCreateInfo   shaderStageParams[]     =
369         {
370                 {
371                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // sType
372                         DE_NULL,                                                                                                // pNext
373                         0u,                                                                                                             // flags
374                         VK_SHADER_STAGE_VERTEX_BIT,                                                             // stage
375                         *vertShaderModule,                                                                              // module
376                         "main",                                                                                                 // pName
377                         &emptyShaderSpecParams,                                                                 // pSpecializationInfo
378                 },
379                 {
380                         VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // sType
381                         DE_NULL,                                                                                                // pNext
382                         0u,                                                                                                             // flags
383                         VK_SHADER_STAGE_FRAGMENT_BIT,                                                   // stage
384                         *fragShaderModule,                                                                              // module
385                         "main",                                                                                                 // pName
386                         &emptyShaderSpecParams,                                                                 // pSpecializationInfo
387                 }
388         };
389         const VkPipelineDepthStencilStateCreateInfo     depthStencilParams              =
390         {
391                 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,     // sType
392                 DE_NULL,                                                                                                        // pNext
393                 0u,                                                                                                                     // flags
394                 DE_FALSE,                                                                                                       // depthTestEnable
395                 DE_FALSE,                                                                                                       // depthWriteEnable
396                 VK_COMPARE_OP_ALWAYS,                                                                           // depthCompareOp
397                 DE_FALSE,                                                                                                       // depthBoundsTestEnable
398                 DE_FALSE,                                                                                                       // stencilTestEnable
399                 {
400                         VK_STENCIL_OP_KEEP,                                                                                     // failOp
401                         VK_STENCIL_OP_KEEP,                                                                                     // passOp
402                         VK_STENCIL_OP_KEEP,                                                                                     // depthFailOp
403                         VK_COMPARE_OP_ALWAYS,                                                                           // compareOp
404                         0u,                                                                                                                     // compareMask
405                         0u,                                                                                                                     // writeMask
406                         0u,                                                                                                                     // reference
407                 },                                                                                                                      // front
408                 {
409                         VK_STENCIL_OP_KEEP,                                                                                     // failOp
410                         VK_STENCIL_OP_KEEP,                                                                                     // passOp
411                         VK_STENCIL_OP_KEEP,                                                                                     // depthFailOp
412                         VK_COMPARE_OP_ALWAYS,                                                                           // compareOp
413                         0u,                                                                                                                     // compareMask
414                         0u,                                                                                                                     // writeMask
415                         0u,                                                                                                                     // reference
416                 },                                                                                                                      // back;
417                 -1.0f,                                                                                                          //      float                           minDepthBounds;
418                 +1.0f,                                                                                                          //      float                           maxDepthBounds;
419         };
420         const VkViewport                                                viewport0                               =
421         {
422                 0.0f,                                                                                                           // x
423                 0.0f,                                                                                                           // y
424                 (float)renderSize.x(),                                                                          // width
425                 (float)renderSize.y(),                                                                          // height
426                 0.0f,                                                                                                           // minDepth
427                 1.0f,                                                                                                           // maxDepth
428         };
429         const VkRect2D                                                  scissor0                                =
430         {
431                 {
432                         0u,                                                                                                                     // x
433                         0u,                                                                                                                     // y
434                 },                                                                                                                      // offset
435                 {
436                         (deUint32)renderSize.x(),                                                                       // width
437                         (deUint32)renderSize.y(),                                                                       // height
438                 },                                                                                                                      // extent;
439         };
440         const VkPipelineViewportStateCreateInfo         viewportParams                  =
441         {
442                 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,          // sType
443                 DE_NULL,                                                                                                        // pNext
444                 0u,                                                                                                                     // flags
445                 1u,                                                                                                                     // viewportCount
446                 &viewport0,                                                                                                     // pViewports
447                 1u,                                                                                                                     // scissorCount
448                 &scissor0                                                                                                       // pScissors
449         };
450         const VkSampleMask                                                      sampleMask                              = ~0u;
451         const VkPipelineMultisampleStateCreateInfo      multisampleParams               =
452         {
453                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // sType
454                 DE_NULL,                                                                                                        // pNext
455                 0u,                                                                                                                     // flags
456                 VK_SAMPLE_COUNT_1_BIT,                                                                          // rasterizationSamples
457                 VK_FALSE,                                                                                                       // sampleShadingEnable
458                 0.0f,                                                                                                           // minSampleShading
459                 &sampleMask,                                                                                            // sampleMask
460                 VK_FALSE,                                                                                                       // alphaToCoverageEnable
461                 VK_FALSE,                                                                                                       // alphaToOneEnable
462         };
463         const VkPipelineRasterizationStateCreateInfo    rasterParams            =
464         {
465                 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,     // sType
466                 DE_NULL,                                                                                                        // pNext
467                 0u,                                                                                                                     // flags
468                 VK_TRUE,                                                                                                        // depthClampEnable
469                 VK_FALSE,                                                                                                       // rasterizerDiscardEnable
470                 VK_POLYGON_MODE_FILL,                                                                           // polygonMode
471                 VK_CULL_MODE_NONE,                                                                                      // cullMode
472                 VK_FRONT_FACE_COUNTER_CLOCKWISE,                                                        // frontFace
473                 VK_FALSE,                                                                                                       // depthBiasEnable
474                 0.0f,                                                                                                           // depthBiasConstantFactor
475                 0.0f,                                                                                                           // depthBiasClamp
476                 0.0f,                                                                                                           // depthBiasSlopeFactor
477                 1.0f,                                                                                                           // lineWidth
478         };
479         const VkPipelineInputAssemblyStateCreateInfo    inputAssemblyParams     =
480         {
481                 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,    // sType
482                 DE_NULL,                                                                                                                // pNext
483                 0u,                                                                                                                             // flags
484                 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,                                                    // topology
485                 DE_FALSE,                                                                                                               // primitiveRestartEnable
486         };
487         const VkVertexInputBindingDescription           vertexBinding0                  =
488         {
489                 0u,                                                                                                             // binding
490                 (deUint32)sizeof(tcu::Vec4),                                                    // stride
491                 VK_VERTEX_INPUT_RATE_VERTEX,                                                    // inputRate
492         };
493         const VkVertexInputAttributeDescription         vertexAttrib0                   =
494         {
495                 0u,                                                                                                             // location
496                 0u,                                                                                                             // binding
497                 VK_FORMAT_R32G32B32A32_SFLOAT,                                                  // format
498                 0u,                                                                                                             // offset
499         };
500         const VkPipelineVertexInputStateCreateInfo      vertexInputStateParams  =
501         {
502                 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,      // sType
503                 DE_NULL,                                                                                                        // pNext
504                 0u,                                                                                                                     // flags
505                 1u,                                                                                                                     // vertexBindingDescriptionCount
506                 &vertexBinding0,                                                                                        // pVertexBindingDescriptions
507                 1u,                                                                                                                     // vertexAttributeDescriptionCount
508                 &vertexAttrib0,                                                                                         // pVertexAttributeDescriptions
509         };
510         const VkPipelineColorBlendAttachmentState       attBlendParams                  =
511         {
512                 VK_FALSE,                                                                                                       // blendEnable
513                 VK_BLEND_FACTOR_ONE,                                                                            // srcColorBlendFactor
514                 VK_BLEND_FACTOR_ZERO,                                                                           // dstColorBlendFactor
515                 VK_BLEND_OP_ADD,                                                                                        // colorBlendOp
516                 VK_BLEND_FACTOR_ONE,                                                                            // srcAlphaBlendFactor
517                 VK_BLEND_FACTOR_ZERO,                                                                           // dstAlphaBlendFactor
518                 VK_BLEND_OP_ADD,                                                                                        // alphaBlendOp
519                 (VK_COLOR_COMPONENT_R_BIT|
520                  VK_COLOR_COMPONENT_G_BIT|
521                  VK_COLOR_COMPONENT_B_BIT|
522                  VK_COLOR_COMPONENT_A_BIT),                                                                     // colorWriteMask
523         };
524         const VkPipelineColorBlendStateCreateInfo       blendParams                             =
525         {
526                 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,       // sType
527                 DE_NULL,                                                                                                        // pNext
528                 0u,                                                                                                                     // flags
529                 DE_FALSE,                                                                                                       // logicOpEnable
530                 VK_LOGIC_OP_COPY,                                                                                       // logicOp
531                 1u,                                                                                                                     // attachmentCount
532                 &attBlendParams,                                                                                        // pAttachments
533                 { 0.0f, 0.0f, 0.0f, 0.0f },                                                                     // blendConstants[4]
534         };
535         const VkPipelineDynamicStateCreateInfo  dynamicStateInfo                =
536         {
537                 VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,   // sType
538                 DE_NULL,                                                                                                // pNext
539                 0u,                                                                                                             // flags
540                 0u,                                                                                                             // dynamicStateCount
541                 DE_NULL                                                                                                 // pDynamicStates
542         };
543         const VkGraphicsPipelineCreateInfo              pipelineParams                  =
544         {
545                 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,                // sType
546                 DE_NULL,                                                                                                // pNext
547                 0u,                                                                                                             // flags
548                 (deUint32)DE_LENGTH_OF_ARRAY(shaderStageParams),                // stageCount
549                 shaderStageParams,                                                                              // pStages
550                 &vertexInputStateParams,                                                                // pVertexInputState
551                 &inputAssemblyParams,                                                                   // pInputAssemblyState
552                 DE_NULL,                                                                                                // pTessellationState
553                 &viewportParams,                                                                                // pViewportState
554                 &rasterParams,                                                                                  // pRasterizationState
555                 &multisampleParams,                                                                             // pMultisampleState
556                 &depthStencilParams,                                                                    // pDepthStencilState
557                 &blendParams,                                                                                   // pColorBlendState
558                 &dynamicStateInfo,                                                                              // pDynamicState
559                 *pipelineLayout,                                                                                // layout
560                 *renderPass,                                                                                    // renderPass
561                 0u,                                                                                                             // subpass
562                 DE_NULL,                                                                                                // basePipelineHandle
563                 0u,                                                                                                             // basePipelineIndex
564         };
565
566         const Unique<VkPipeline>                                pipeline                                (createGraphicsPipeline(vk, vkDevice, DE_NULL, &pipelineParams));
567
568         // Framebuffer
569         const VkFramebufferCreateInfo                   framebufferParams               =
570         {
571                 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,                              // sType
572                 DE_NULL,                                                                                                // pNext
573                 0u,                                                                                                             // flags
574                 *renderPass,                                                                                    // renderPass
575                 1u,                                                                                                             // attachmentCount
576                 &*colorAttView,                                                                                 // pAttachments
577                 (deUint32)renderSize.x(),                                                               // width
578                 (deUint32)renderSize.y(),                                                               // height
579                 1u,                                                                                                             // layers
580         };
581         const Unique<VkFramebuffer>                             framebuffer                             (createFramebuffer(vk, vkDevice, &framebufferParams));
582
583         const VkCommandPoolCreateInfo                   cmdPoolParams                   =
584         {
585                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // sType
586                 DE_NULL,                                                                                                        // pNext
587                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,                        // flags
588                 queueFamilyIndex,                                                                                       // queueFamilyIndex
589         };
590         const Unique<VkCommandPool>                             cmdPool                                 (createCommandPool(vk, vkDevice, &cmdPoolParams));
591
592         // Command buffer
593         const VkCommandBufferAllocateInfo               cmdBufParams                    =
594         {
595                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                 // sType
596                 DE_NULL,                                                                                                // pNext
597                 *cmdPool,                                                                                               // pool
598                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                // level
599                 1u,                                                                                                             // bufferCount
600         };
601         const Unique<VkCommandBuffer>                   cmdBuf                                  (allocateCommandBuffer(vk, vkDevice, &cmdBufParams));
602
603         const VkCommandBufferBeginInfo                  cmdBufBeginParams               =
604         {
605                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // sType
606                 DE_NULL,                                                                                                // pNext
607                 0u,                                                                                                             // flags
608                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
609         };
610
611         // Record commands
612         VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginParams));
613
614         {
615                 const VkMemoryBarrier           vertFlushBarrier        =
616                 {
617                         VK_STRUCTURE_TYPE_MEMORY_BARRIER,                       // sType
618                         DE_NULL,                                                                        // pNext
619                         VK_ACCESS_HOST_WRITE_BIT,                                       // srcAccessMask
620                         VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT,            // dstAccessMask
621                 };
622                 const VkImageMemoryBarrier      colorAttBarrier         =
623                 {
624                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // sType
625                         DE_NULL,                                                                        // pNext
626                         0u,                                                                                     // srcAccessMask
627                         (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT|
628                          VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT),         // dstAccessMask
629                         VK_IMAGE_LAYOUT_UNDEFINED,                                      // oldLayout
630                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // newLayout
631                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
632                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
633                         *image,                                                                         // image
634                         {
635                                 VK_IMAGE_ASPECT_COLOR_BIT,                                      // aspectMask
636                                 0u,                                                                                     // baseMipLevel
637                                 1u,                                                                                     // levelCount
638                                 0u,                                                                                     // baseArrayLayer
639                                 1u,                                                                                     // layerCount
640                         }                                                                                       // subresourceRange
641                 };
642                 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);
643         }
644
645         {
646                 const VkClearValue                      clearValue              = makeClearValueColorF32(0.125f, 0.25f, 0.75f, 1.0f);
647                 const VkRenderPassBeginInfo     passBeginParams =
648                 {
649                         VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,                       // sType
650                         DE_NULL,                                                                                        // pNext
651                         *renderPass,                                                                            // renderPass
652                         *framebuffer,                                                                           // framebuffer
653                         {
654                                 { 0, 0 },
655                                 { (deUint32)renderSize.x(), (deUint32)renderSize.y() }
656                         },                                                                                                      // renderArea
657                         1u,                                                                                                     // clearValueCount
658                         &clearValue,                                                                            // pClearValues
659                 };
660                 vk.cmdBeginRenderPass(*cmdBuf, &passBeginParams, VK_SUBPASS_CONTENTS_INLINE);
661         }
662
663         vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
664         {
665                 const VkDeviceSize bindingOffset = 0;
666                 vk.cmdBindVertexBuffers(*cmdBuf, 0u, 1u, &vertexBuffer.get(), &bindingOffset);
667         }
668         vk.cmdDraw(*cmdBuf, 3u, 1u, 0u, 0u);
669         vk.cmdEndRenderPass(*cmdBuf);
670
671         {
672                 const VkImageMemoryBarrier      renderFinishBarrier     =
673                 {
674                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // sType
675                         DE_NULL,                                                                        // pNext
676                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,           // outputMask
677                         VK_ACCESS_TRANSFER_READ_BIT,                            // inputMask
678                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // oldLayout
679                         VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,           // newLayout
680                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
681                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
682                         *image,                                                                         // image
683                         {
684                                 VK_IMAGE_ASPECT_COLOR_BIT,                                      // aspectMask
685                                 0u,                                                                                     // baseMipLevel
686                                 1u,                                                                                     // mipLevels
687                                 0u,                                                                                     // baseArraySlice
688                                 1u,                                                                                     // arraySize
689                         }                                                                                       // subresourceRange
690                 };
691                 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);
692         }
693
694         {
695                 const VkBufferImageCopy copyParams      =
696                 {
697                         (VkDeviceSize)0u,                                               // bufferOffset
698                         (deUint32)renderSize.x(),                               // bufferRowLength
699                         (deUint32)renderSize.y(),                               // bufferImageHeight
700                         {
701                                 VK_IMAGE_ASPECT_COLOR_BIT,                              // aspectMask
702                                 0u,                                                                             // mipLevel
703                                 0u,                                                                             // baseArrayLayer
704                                 1u,                                                                             // layerCount
705                         },                                                                              // imageSubresource
706                         { 0u, 0u, 0u },                                                 // imageOffset
707                         {
708                                 (deUint32)renderSize.x(),
709                                 (deUint32)renderSize.y(),
710                                 1u
711                         }                                                                               // imageExtent
712                 };
713                 vk.cmdCopyImageToBuffer(*cmdBuf, *image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *readImageBuffer, 1u, &copyParams);
714         }
715
716         {
717                 const VkBufferMemoryBarrier     copyFinishBarrier       =
718                 {
719                         VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // sType
720                         DE_NULL,                                                                        // pNext
721                         VK_ACCESS_TRANSFER_WRITE_BIT,                           // srcAccessMask
722                         VK_ACCESS_HOST_READ_BIT,                                        // dstAccessMask
723                         queueFamilyIndex,                                                       // srcQueueFamilyIndex
724                         queueFamilyIndex,                                                       // dstQueueFamilyIndex
725                         *readImageBuffer,                                                       // buffer
726                         0u,                                                                                     // offset
727                         imageSizeBytes                                                          // size
728                 };
729                 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);
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                         (const VkPipelineStageFlags*)DE_NULL,
765                         1u,                                                                             // commandBufferCount
766                         &cmdBuf.get(),                                                  // pCommandBuffers
767                         0u,                                                                             // signalSemaphoreCount
768                         DE_NULL,                                                                // pSignalSemaphores
769                 };
770                 const Unique<VkFence>   fence           (createFence(vk, vkDevice, &fenceParams));
771
772                 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
773                 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), DE_TRUE, ~0ull));
774         }
775
776         // Log image
777         {
778                 const VkMappedMemoryRange       range           =
779                 {
780                         VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,  // sType
781                         DE_NULL,                                                                // pNext
782                         readImageBufferMemory->getMemory(),             // memory
783                         0,                                                                              // offset
784                         imageSizeBytes,                                                 // size
785                 };
786                 void*                                           imagePtr        = readImageBufferMemory->getHostPtr();
787
788                 VK_CHECK(vk.invalidateMappedMemoryRanges(vkDevice, 1u, &range));
789                 context.getTestContext().getLog() << TestLog::Image("Result", "Result", tcu::ConstPixelBufferAccess(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), renderSize.x(), renderSize.y(), 1, imagePtr));
790         }
791
792         return tcu::TestStatus::pass("Rendering succeeded");
793 }
794
795 } // anonymous
796
797 tcu::TestCaseGroup* createSmokeTests (tcu::TestContext& testCtx)
798 {
799         de::MovePtr<tcu::TestCaseGroup> smokeTests      (new tcu::TestCaseGroup(testCtx, "smoke", "Smoke Tests"));
800
801         addFunctionCase                         (smokeTests.get(), "create_sampler",    "",     createSamplerTest);
802         addFunctionCaseWithPrograms     (smokeTests.get(), "create_shader",             "", createShaderProgs,          createShaderModuleTest);
803         addFunctionCaseWithPrograms     (smokeTests.get(), "triangle",                  "", createTriangleProgs,        renderTriangleTest);
804         addFunctionCaseWithPrograms     (smokeTests.get(), "asm_triangle",              "", createTriangleAsmProgs,     renderTriangleTest);
805
806         return smokeTests.release();
807 }
808
809 } // api
810 } // vkt