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