Merge branch 'jekstrand_renderpass_transfer_bit_fix' into 'master'
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / api / vktApiBufferViewAccessTests.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 The Khronos Group Inc.
6  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and/or associated documentation files (the
10  * "Materials"), to deal in the Materials without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Materials, and to
13  * permit persons to whom the Materials are furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice(s) and this permission notice shall be included
17  * in all copies or substantial portions of the Materials.
18  *
19  * The Materials are Confidential Information as defined by the
20  * Khronos Membership Agreement until designated non-confidential by Khronos,
21  * at which point this condition clause shall be removed.
22  *
23  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
30  *
31  *//*!
32  * \file
33  * \brief Vulkan Buffer View Memory Tests
34  *//*--------------------------------------------------------------------*/
35
36 #include "vktApiBufferViewAccessTests.hpp"
37
38 #include "deStringUtil.hpp"
39 #include "deUniquePtr.hpp"
40 #include "vktTestCase.hpp"
41 #include "vktTestCaseUtil.hpp"
42 #include "vkImageUtil.hpp"
43 #include "vkMemUtil.hpp"
44 #include "vkPrograms.hpp"
45 #include "vkQueryUtil.hpp"
46 #include "vkRef.hpp"
47 #include "vkRefUtil.hpp"
48 #include "vkTypeUtil.hpp"
49 #include "tcuImageCompare.hpp"
50 #include "tcuTexture.hpp"
51 #include "tcuTextureUtil.hpp"
52
53 namespace vkt
54 {
55
56 namespace api
57 {
58
59 using namespace vk;
60
61 namespace
62 {
63
64 struct BufferViewCaseParams
65 {
66         deUint32        bufferSize;
67         deUint32        bufferViewSize;
68         deUint32        elementOffset;
69 };
70
71 class BufferViewTestInstance : public vkt::TestInstance
72 {
73 public:
74                                                                                 BufferViewTestInstance          (Context&                               context,
75                                                                                                                                          BufferViewCaseParams   testCase);
76         virtual                                                         ~BufferViewTestInstance         (void);
77         virtual tcu::TestStatus                         iterate                                         (void);
78
79 private:
80         void                                                            createQuad                                      (void);
81         tcu::TestStatus                                         checkResult                                     (deInt8 factor = 1);
82
83 private:
84         BufferViewCaseParams                            m_testCase;
85
86         const tcu::IVec2                                        m_renderSize;
87         const VkFormat                                          m_colorFormat;
88
89         const VkDeviceSize                                      m_pixelDataSize;
90
91         Move<VkImage>                                           m_colorImage;
92         de::MovePtr<Allocation>                         m_colorImageAlloc;
93         Move<VkImageView>                                       m_colorAttachmentView;
94         Move<VkRenderPass>                                      m_renderPass;
95         Move<VkFramebuffer>                                     m_framebuffer;
96
97         Move<VkDescriptorSetLayout>                     m_descriptorSetLayout;
98         Move<VkDescriptorPool>                          m_descriptorPool;
99         Move<VkDescriptorSet>                           m_descriptorSet;
100
101         Move<VkBuffer>                                          m_uniformBuffer;
102         de::MovePtr<vk::Allocation>                     m_uniformBufferAlloc;
103         Move<VkBufferView>                                      m_uniformBufferView;
104
105         Move<VkShaderModule>                            m_vertexShaderModule;
106         Move<VkShaderModule>                            m_fragmentShaderModule;
107
108         Move<VkBuffer>                                          m_vertexBuffer;
109         std::vector<tcu::Vec4>                          m_vertices;
110         de::MovePtr<Allocation>                         m_vertexBufferAlloc;
111
112         Move<VkPipelineLayout>                          m_pipelineLayout;
113         Move<VkPipeline>                                        m_graphicsPipelines;
114
115         Move<VkCommandPool>                                     m_cmdPool;
116         Move<VkCommandBuffer>                           m_cmdBuffer;
117
118         Move<VkBuffer>                                          m_resultBuffer;
119         de::MovePtr<Allocation>                         m_resultBufferAlloc;
120
121         Move<VkFence>                                           m_fence;
122 };
123
124 static void generateBuffer (std::vector<deUint32>& uniformData, deUint32 bufferSize, deInt8 factor = 1)
125 {
126         for (deUint32 i = 0; i < bufferSize; ++i)
127                 uniformData.push_back(factor * i);
128 }
129
130 void BufferViewTestInstance::createQuad (void)
131 {
132         tcu::Vec4 a(-1.0, -1.0, 0.0, 1.0);
133         tcu::Vec4 b(1.0, -1.0, 0.0, 1.0);
134         tcu::Vec4 c(1.0, 1.0, 0.0, 1.0);
135         tcu::Vec4 d(-1.0, 1.0, 0.0, 1.0);
136
137         // Triangle 1
138         m_vertices.push_back(a);
139         m_vertices.push_back(c);
140         m_vertices.push_back(b);
141
142         // Triangle 2
143         m_vertices.push_back(c);
144         m_vertices.push_back(a);
145         m_vertices.push_back(d);
146 }
147
148 BufferViewTestInstance::~BufferViewTestInstance (void)
149 {
150 }
151
152 BufferViewTestInstance::BufferViewTestInstance (Context& context, BufferViewCaseParams testCase)
153         : vkt::TestInstance             (context)
154         , m_testCase                    (testCase)
155         , m_renderSize                  (testCase.bufferViewSize, testCase.bufferViewSize)
156         , m_colorFormat                 (VK_FORMAT_R32_UINT)
157         , m_pixelDataSize               (m_renderSize.x() * m_renderSize.y() * mapVkFormat(m_colorFormat).getPixelSize())
158 {
159         const DeviceInterface&          vk                                      = context.getDeviceInterface();
160         const VkDevice                          vkDevice                        = context.getDevice();
161         const deUint32                          queueFamilyIndex        = context.getUniversalQueueFamilyIndex();
162         SimpleAllocator                         memAlloc                        (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
163         const VkComponentMapping        channelMappingRGBA      = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
164
165         // Create color image
166         {
167                 const VkImageCreateInfo colorImageParams =
168                 {
169                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                                            // VkStructureType              sType;
170                         DE_NULL,                                                                                                                                        // const void*                  pNext;
171                         0u,                                                                                                                                                     // VkImageCreateFlags   flags;
172                         VK_IMAGE_TYPE_2D,                                                                                                                       // VkImageType                  imageType;
173                         m_colorFormat,                                                                                                                          // VkFormat                             format;
174                         { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y(), 1u },                         // VkExtent3D                   extent;
175                         1u,                                                                                                                                                     // deUint32                             mipLevels;
176                         1u,                                                                                                                                                     // deUint32                             arraySize;
177                         VK_SAMPLE_COUNT_1_BIT,                                                                                                          // deUint32                             samples;
178                         VK_IMAGE_TILING_OPTIMAL,                                                                                                        // VkImageTiling                tiling;
179                         VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,          // VkImageUsageFlags    usage;
180                         VK_SHARING_MODE_EXCLUSIVE,                                                                                                      // VkSharingMode                sharingMode;
181                         1u,                                                                                                                                                     // deUint32                             queueFamilyCount;
182                         &queueFamilyIndex,                                                                                                                      // const deUint32*              pQueueFamilyIndices;
183                         VK_IMAGE_LAYOUT_UNDEFINED,                                                                                                      // VkImageLayout                initialLayout;
184                 };
185
186                 m_colorImage                    = createImage(vk, vkDevice, &colorImageParams);
187
188                 // Allocate and bind color image memory
189                 m_colorImageAlloc               = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_colorImage), MemoryRequirement::Any);
190                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_colorImage, m_colorImageAlloc->getMemory(), m_colorImageAlloc->getOffset()));
191         }
192
193         // Create destination buffer
194         {
195                 const VkBufferCreateInfo bufferParams =
196                 {
197                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
198                         DE_NULL,                                                                        // const void*                  pNext;
199                         0u,                                                                                     // VkBufferCreateFlags  flags;
200                         m_pixelDataSize,                                                        // VkDeviceSize                 size;
201                         VK_BUFFER_USAGE_TRANSFER_DST_BIT,                  // VkBufferUsageFlags        usage;
202                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
203                         0u,                                                                                     // deUint32                             queueFamilyCount;
204                         DE_NULL,                                                                        // const deUint32*              pQueueFamilyIndices;
205                 };
206
207                 m_resultBuffer          = createBuffer(vk, vkDevice, &bufferParams);
208                 m_resultBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_resultBuffer), MemoryRequirement::HostVisible);
209
210                 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_resultBuffer, m_resultBufferAlloc->getMemory(), m_resultBufferAlloc->getOffset()));
211         }
212
213         // Create color attachment view
214         {
215                 const VkImageViewCreateInfo colorAttachmentViewParams =
216                 {
217                         VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,                       // VkStructureType                      sType;
218                         DE_NULL,                                                                                        // const void*                          pNext;
219                         0u,                                                                                                     // VkImageViewCreateFlags       flags;
220                         *m_colorImage,                                                                          // VkImage                                      image;
221                         VK_IMAGE_VIEW_TYPE_2D,                                                          // VkImageViewType                      viewType;
222                         m_colorFormat,                                                                          // VkFormat                                     format;
223                         channelMappingRGBA,                                                                     // VkChannelMapping                     channels;
224                         { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u },          // VkImageSubresourceRange      subresourceRange;
225                 };
226
227                 m_colorAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
228         }
229
230         // Create render pass
231         {
232                 const VkAttachmentDescription colorAttachmentDescription =
233                 {
234                         0u,                                                                                                     // VkAttachmentDescriptionFlags flags;
235                         m_colorFormat,                                                                          // VkFormat                                             format;
236                         VK_SAMPLE_COUNT_1_BIT,                                                          // deUint32                                             samples;
237                         VK_ATTACHMENT_LOAD_OP_CLEAR,                                            // VkAttachmentLoadOp                   loadOp;
238                         VK_ATTACHMENT_STORE_OP_STORE,                                           // VkAttachmentStoreOp                  storeOp;
239                         VK_ATTACHMENT_LOAD_OP_DONT_CARE,                                        // VkAttachmentLoadOp                   stencilLoadOp;
240                         VK_ATTACHMENT_STORE_OP_DONT_CARE,                                       // VkAttachmentStoreOp                  stencilStoreOp;
241                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,                       // VkImageLayout                                initialLayout;
242                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,                       // VkImageLayout                                finalLayout;
243                 };
244
245                 const VkAttachmentReference colorAttachmentReference =
246                 {
247                         0u,                                                                                                     // deUint32                     attachment;
248                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL                        // VkImageLayout        layout;
249                 };
250
251                 const VkSubpassDescription subpassDescription =
252                 {
253                         0u,                                                                                                     // VkSubpassDescriptionFlags            flags;
254                         VK_PIPELINE_BIND_POINT_GRAPHICS,                                        // VkPipelineBindPoint                          pipelineBindPoint;
255                         0u,                                                                                                     // deUint32                                                     inputCount;
256                         DE_NULL,                                                                                        // const VkAttachmentReference*         pInputAttachments;
257                         1u,                                                                                                     // deUint32                                                     colorCount;
258                         &colorAttachmentReference,                                                      // const VkAttachmentReference*         pColorAttachments;
259                         DE_NULL,                                                                                        // const VkAttachmentReference*         pResolveAttachments;
260                         DE_NULL,                                                                                        // VkAttachmentReference                        depthStencilAttachment;
261                         0u,                                                                                                     // deUint32                                                     preserveCount;
262                         DE_NULL                                                                                         // const VkAttachmentReference*         pPreserveAttachments;
263                 };
264
265                 const VkRenderPassCreateInfo renderPassParams =
266                 {
267                         VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,                      // VkStructureType                                      sType;
268                         DE_NULL,                                                                                        // const void*                                          pNext;
269                         (VkRenderPassCreateFlags)0,
270                         1u,                                                                                                     // deUint32                                                     attachmentCount;
271                         &colorAttachmentDescription,                                            // const VkAttachmentDescription*       pAttachments;
272                         1u,                                                                                                     // deUint32                                                     subpassCount;
273                         &subpassDescription,                                                            // const VkSubpassDescription*          pSubpasses;
274                         0u,                                                                                                     // deUint32                                                     dependencyCount;
275                         DE_NULL                                                                                         // const VkSubpassDependency*           pDependencies;
276                 };
277
278                 m_renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
279         }
280
281         // Create framebuffer
282         {
283                 const VkImageView attachmentBindInfos[1] =
284                 {
285                         *m_colorAttachmentView,
286                 };
287
288                 const VkFramebufferCreateInfo framebufferParams =
289                 {
290                         VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,                      // VkStructureType                              sType;
291                         DE_NULL,                                                                                        // const void*                                  pNext;
292                         (VkFramebufferCreateFlags)0,
293                         *m_renderPass,                                                                          // VkRenderPass                                 renderPass;
294                         1u,                                                                                                     // deUint32                                             attachmentCount;
295                         attachmentBindInfos,                                                            // const VkImageView*                   pAttachments;
296                         (deUint32)m_renderSize.x(),                                                     // deUint32                                             width;
297                         (deUint32)m_renderSize.y(),                                                     // deUint32                                             height;
298                         1u                                                                                                      // deUint32                                             layers;
299                 };
300
301                 m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
302         }
303
304         // Create descriptors
305         {
306                 const VkDescriptorSetLayoutBinding layoutBindings[1] =
307                 {
308                         {
309                                 0u,                                                                                     // deUint32                             binding;
310                                 VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,        // VkDescriptorType             descriptorType;
311                                 1u,                                                                                     // deUint32                             arraySize;
312                                 VK_SHADER_STAGE_ALL,                                            // VkShaderStageFlags   stageFlags;
313                                 DE_NULL                                                                         // const VkSampler*             pImmutableSamplers;
314                         },
315                 };
316
317                 const VkDescriptorSetLayoutCreateInfo descriptorLayoutParams =
318                 {
319                         VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,    // VkStructureType                                              sType;
320                         DE_NULL,                                                                                                // cost void*                                                   pNexŧ;
321                         (VkDescriptorSetLayoutCreateFlags)0,
322                         DE_LENGTH_OF_ARRAY(layoutBindings),                                             // deUint32                                                             count;
323                         layoutBindings                                                                                  // const VkDescriptorSetLayoutBinding   pBinding;
324                 };
325
326                 m_descriptorSetLayout = createDescriptorSetLayout(vk, vkDevice, &descriptorLayoutParams);
327
328                 // Generate buffer
329                 std::vector<deUint32> uniformData;
330                 generateBuffer(uniformData, testCase.bufferSize);
331
332                 const VkDeviceSize uniformSize = testCase.bufferSize * sizeof(deUint32);
333                 const VkBufferCreateInfo uniformBufferParams =
334                 {
335                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
336                         DE_NULL,                                                                        // const void*                  pNext;
337                         0u,                                                                                     // VkBufferCreateFlags  flags; <-- TODO: 0u?
338                         uniformSize,                                                            // VkDeviceSize                 size;
339                         VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT,       // VkBufferUsageFlags   usage;
340                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
341                         1u,                                                                                     // deUint32                             queueFamilyIndexCount;
342                         &queueFamilyIndex                                                       // const deUint32*              pQueueFamilyIndices;
343                 };
344
345                 m_uniformBuffer                 = createBuffer(vk, vkDevice, &uniformBufferParams);
346                 m_uniformBufferAlloc    = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_uniformBuffer), MemoryRequirement::HostVisible);
347
348                 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_uniformBuffer, m_uniformBufferAlloc->getMemory(), 0));
349                 deMemcpy(m_uniformBufferAlloc->getHostPtr(), uniformData.data(), (size_t)uniformSize);
350
351                 const VkBufferViewCreateInfo viewInfo =
352                 {
353                         VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO,                                                      // VkStructureType      sType;
354                         DE_NULL,                                                                                                                        // void*                        pNext;
355                         (VkBufferViewCreateFlags)0,
356                         *m_uniformBuffer,                                                                                                       // VkBuffer                     buffer;
357                         m_colorFormat,                                                                                                          // VkFormat                     format;
358                         m_testCase.elementOffset * sizeof(deUint32),                                            // VkDeviceSize         offset;
359                         m_testCase.bufferViewSize * sizeof(deUint32)                                            // VkDeviceSize         range;
360                 };
361
362                 m_uniformBufferView = createBufferView(vk, vkDevice, &viewInfo);
363
364                 const VkDescriptorPoolSize descriptorTypes[1] =
365                 {
366                         {
367                                 VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,                // VkDescriptorType             type;
368                                 1                                                                                               // deUint32                             count;
369                         }
370                 };
371
372                 const VkDescriptorPoolCreateInfo descriptorPoolParams =
373                 {
374                         VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,          // VkStructureType                                      sType;
375                         DE_NULL,                                                                                        // void*                                                        pNext;
376                         VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,      // VkDescriptorPoolCreateFlags          flags;
377                         1u,                                                                                                     // uint32_t                                                     maxSets;
378                         DE_LENGTH_OF_ARRAY(descriptorTypes),                            // deUint32                                                     count;
379                         descriptorTypes                                                                         // const VkDescriptorTypeCount*         pTypeCount
380                 };
381
382                 m_descriptorPool = createDescriptorPool(vk, vkDevice, &descriptorPoolParams);
383
384                 const VkDescriptorSetAllocateInfo descriptorSetParams =
385                 {
386                         VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
387                         DE_NULL,
388                         *m_descriptorPool,
389                         1u,
390                         &m_descriptorSetLayout.get(),
391                 };
392                 m_descriptorSet = allocateDescriptorSet(vk, vkDevice, &descriptorSetParams);
393
394                 const VkWriteDescriptorSet writeDescritporSets[] =
395                 {
396                         {
397                                 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,         // VkStructureType                      sType;
398                                 DE_NULL,                                                                        // const void*                          pNext;
399                                 *m_descriptorSet,                                                       // VkDescriptorSet                      destSet;
400                                 0,                                                                                      // deUint32                                     destBinding;
401                                 0,                                                                                      // deUint32                                     destArrayElement;
402                                 1u,                                                                                     // deUint32                                     count;
403                                 VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,        // VkDescriptorType                     descriptorType;
404                                 (const VkDescriptorImageInfo*)DE_NULL,
405                                 (const VkDescriptorBufferInfo*)DE_NULL,
406                                 &m_uniformBufferView.get(),
407                         }
408                 };
409
410                 vk.updateDescriptorSets(vkDevice, DE_LENGTH_OF_ARRAY(writeDescritporSets), writeDescritporSets, 0u, DE_NULL);
411         }
412
413         // Create pipeline layout
414         {
415                 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
416                 {
417                         VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,          // VkStructureType                              sType;
418                         DE_NULL,                                                                                        // const void*                                  pNext;
419                         (VkPipelineLayoutCreateFlags)0,
420                         1u,                                                                                                     // deUint32                                             descriptorSetCount;
421                         &*m_descriptorSetLayout,                                                        // const VkDescriptorSetLayout* pSetLayouts;
422                         0u,                                                                                                     // deUint32                                             pushConstantRangeCount;
423                         DE_NULL                                                                                         // const VkPushConstantRange*   pPushConstantRanges;
424                 };
425
426                 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
427         }
428
429         // Create shaders
430         {
431                 m_vertexShaderModule    = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("vert"), 0);
432                 m_fragmentShaderModule  = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("frag"), 0);
433         }
434
435         // Create pipeline
436         {
437
438                 const VkPipelineShaderStageCreateInfo shaderStageParams[2] =
439                 {
440                         {
441                                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,            // VkStructureType                              sType;
442                                 DE_NULL,                                                                                                        // const void*                                  pNext;
443                                 (VkPipelineShaderStageCreateFlags)0,
444                                 VK_SHADER_STAGE_VERTEX_BIT,                                                                     // VkShaderStage                                stage;
445                                 *m_vertexShaderModule,                                                                          // VkShader                                             shader;
446                                 "main",
447                                 DE_NULL                                                                                                         // const VkSpecializationInfo*  pSpecializationInfo;
448                         },
449                         {
450                                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,            // VkStructureType                              sType;
451                                 DE_NULL,                                                                                                        // const void*                                  pNext;
452                                 (VkPipelineShaderStageCreateFlags)0,
453                                 VK_SHADER_STAGE_FRAGMENT_BIT,                                                           // VkShaderStage                                stage;
454                                 *m_fragmentShaderModule,                                                                        // VkShader                                             shader;
455                                 "main",
456                                 DE_NULL                                                                                                         // const VkSpecializationInfo*  pSpecializationInfo;
457                         }
458                 };
459
460                 const VkVertexInputBindingDescription vertexInputBindingDescription =
461                 {
462                         0u,                                                             // deUint32                                     binding;
463                         sizeof(tcu::Vec4),                              // deUint32                                     strideInBytes;
464                         VK_VERTEX_INPUT_RATE_VERTEX             // VkVertexInputStepRate        stepRate;
465                 };
466
467                 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[1] =
468                 {
469                         {
470                                 0u,                                                                     // deUint32     location;
471                                 0u,                                                                     // deUint32     binding;
472                                 VK_FORMAT_R32G32B32A32_SFLOAT,          // VkFormat     format;
473                                 0u                                                                      // deUint32     offsetInBytes;
474                         }
475                 };
476
477                 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
478                 {
479                         VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,              // VkStructureType                                                      sType;
480                         DE_NULL,                                                                                                                // const void*                                                          pNext;
481                         (VkPipelineVertexInputStateCreateFlags)0,
482                         1u,                                                                                                                             // deUint32                                                                     bindingCount;
483                         &vertexInputBindingDescription,                                                                 // const VkVertexInputBindingDescription*       pVertexBindingDescriptions;
484                         1u,                                                                                                                             // deUint32                                                                     attributeCount;
485                         vertexInputAttributeDescriptions                                                                // const VkVertexInputAttributeDescription*     pVertexAttributeDescriptions;
486                 };
487
488                 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
489                 {
490                         VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,    // VkStructureType              sType;
491                         DE_NULL,                                                                                                                // const void*                  pNext;
492                         (VkPipelineInputAssemblyStateCreateFlags)0,
493                         VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,                                                    // VkPrimitiveTopology  topology;
494                         false                                                                                                                   // VkBool32                             primitiveRestartEnable;
495                 };
496
497                 const VkViewport viewport =
498                 {
499                         0.0f,                                           // float        originX;
500                         0.0f,                                           // float        originY;
501                         (float)m_renderSize.x(),        // float        width;
502                         (float)m_renderSize.y(),        // float        height;
503                         0.0f,                                           // float        minDepth;
504                         1.0f                                            // float        maxDepth;
505                 };
506                 const VkRect2D scissor =
507                 {
508                         { 0, 0 },                                                                                                       // VkOffset2D  offset;
509                         { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() }      // VkExtent2D  extent;
510                 };
511                 const VkPipelineViewportStateCreateInfo viewportStateParams =
512                 {
513                         VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,                  // VkStructureType              sType;
514                         DE_NULL,                                                                                                                // const void*                  pNext;
515                         (VkPipelineViewportStateCreateFlags)0,
516                         1u,                                                                                                                             // deUint32                             viewportCount;
517                         &viewport,                                                                                                              // const VkViewport*    pViewports;
518                         1u,                                                                                                                             // deUint32                             scissorCount;
519                         &scissor                                                                                                                // const VkRect2D*              pScissors;
520                 };
521
522                 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
523                 {
524                         VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,             // VkStructureType      sType;
525                         DE_NULL,                                                                                                                // const void*          pNext;
526                         (VkPipelineRasterizationStateCreateFlags)0,
527                         false,                                                                                                                  // VkBool32                     depthClipEnable;
528                         false,                                                                                                                  // VkBool32                     rasterizerDiscardEnable;
529                         VK_POLYGON_MODE_FILL,                                                                                   // VkFillMode           fillMode;
530                         VK_CULL_MODE_NONE,                                                                                              // VkCullMode           cullMode;
531                         VK_FRONT_FACE_COUNTER_CLOCKWISE,                                                                // VkFrontFace          frontFace;
532                         VK_FALSE,                                                                                                               // VkBool32                     depthBiasEnable;
533                         0.0f,                                                                                                                   // float                        depthBias;
534                         0.0f,                                                                                                                   // float                        depthBiasClamp;
535                         0.0f,                                                                                                                   // float                        slopeScaledDepthBias;
536                         1.0f,                                                                                                                   // float                        lineWidth;
537                 };
538
539                 const VkPipelineMultisampleStateCreateInfo              multisampleStateParams =
540                 {
541                         VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,               // VkStructureType                                                      sType;
542                         DE_NULL,                                                                                                                // const void*                                                          pNext;
543                         0u,                                                                                                                             // VkPipelineMultisampleStateCreateFlags        flags;
544                         VK_SAMPLE_COUNT_1_BIT,                                                                                  // VkSampleCountFlagBits                                        rasterizationSamples;
545                         VK_FALSE,                                                                                                               // VkBool32                                                                     sampleShadingEnable;
546                         0.0f,                                                                                                                   // float                                                                        minSampleShading;
547                         DE_NULL,                                                                                                                // const VkSampleMask*                                          pSampleMask;
548                         VK_FALSE,                                                                                                               // VkBool32                                                                     alphaToCoverageEnable;
549                         VK_FALSE                                                                                                                // VkBool32                                                                     alphaToOneEnable;
550                 };
551
552                 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
553                 {
554                         false,                                                                                                          // VkBool32                     blendEnable;
555                         VK_BLEND_FACTOR_ONE,                                                                            // VkBlend                      srcBlendColor;
556                         VK_BLEND_FACTOR_ZERO,                                                                           // VkBlend                      destBlendColor;
557                         VK_BLEND_OP_ADD,                                                                                        // VkBlendOp            blendOpColor;
558                         VK_BLEND_FACTOR_ONE,                                                                            // VkBlend                      srcBlendAlpha;
559                         VK_BLEND_FACTOR_ZERO,                                                                           // VkBlend                      destBlendAlpha;
560                         VK_BLEND_OP_ADD,                                                                                        // VkBlendOp            blendOpAlpha;
561                         (VK_COLOR_COMPONENT_R_BIT |
562                          VK_COLOR_COMPONENT_G_BIT |
563                          VK_COLOR_COMPONENT_B_BIT |
564                          VK_COLOR_COMPONENT_A_BIT)                                                                      // VkChannelFlags       channelWriteMask;
565                 };
566
567                 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
568                 {
569                         VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,       // VkStructureType                                                              sType;
570                         DE_NULL,                                                                                                        // const void*                                                                  pNext;
571                         (VkPipelineColorBlendStateCreateFlags)0,
572                         false,                                                                                                          // VkBool32                                                                             logicOpEnable;
573                         VK_LOGIC_OP_COPY,                                                                                       // VkLogicOp                                                                    logicOp;
574                         1u,                                                                                                                     // deUint32                                                                             attachmentCount;
575                         &colorBlendAttachmentState,                                                                     // const VkPipelineColorBlendAttachmentState*   pAttachments;
576                         { 0.0f, 0.0f, 0.0f, 0.0f },                                                                     // float                                                                                blendConst[4];
577                 };
578
579                 const VkPipelineDynamicStateCreateInfo  dynamicStateParams              =
580                 {
581                         VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,           // VkStructureType                      sType;
582                         DE_NULL,                                                                                                        // const void*                          pNext;
583                         (VkPipelineDynamicStateCreateFlags)0,
584                         0u,                                                                                                                     // deUint32                                     dynamicStateCount;
585                         DE_NULL                                                                                                         // const VkDynamicState*        pDynamicStates;
586                 };
587
588                 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
589                 {
590                         VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,        // VkStructureType                                                                      sType;
591                         DE_NULL,                                                                                        // const void*                                                                          pNext;
592                         0u,                                                                                                     // VkPipelineCreateFlags                                                        flags;
593                         2u,                                                                                                     // deUint32                                                                                     stageCount;
594                         shaderStageParams,                                                                      // const VkPipelineShaderStageCreateInfo*                       pStages;
595                         &vertexInputStateParams,                                                        // const VkPipelineVertexInputStateCreateInfo*          pVertexInputState;
596                         &inputAssemblyStateParams,                                                      // const VkPipelineInputAssemblyStateCreateInfo*        pInputAssemblyState;
597                         DE_NULL,                                                                                        // const VkPipelineTessellationStateCreateInfo*         pTessellationState;
598                         &viewportStateParams,                                                           // const VkPipelineViewportStateCreateInfo*                     pViewportState;
599                         &rasterStateParams,                                                                     // const VkPipelineRasterStateCreateInfo*                       pRasterState;
600                         &multisampleStateParams,                                                        // const VkPipelineMultisampleStateCreateInfo*          pMultisampleState;
601                         DE_NULL,                                                                                        // const VkPipelineDepthStencilStateCreateInfo*         pDepthStencilState;
602                         &colorBlendStateParams,                                                         // const VkPipelineColorBlendStateCreateInfo*           pColorBlendState;
603                         &dynamicStateParams,                                                            // const VkPipelineDynamicStateCreateInfo*                      pDynamicState;
604                         *m_pipelineLayout,                                                                      // VkPipelineLayout                                                                     layout;
605                         *m_renderPass,                                                                          // VkRenderPass                                                                         renderPass;
606                         0u,                                                                                                     // deUint32                                                                                     subpass;
607                         0u,                                                                                                     // VkPipeline                                                                           basePipelineHandle;
608                         0u                                                                                                      // deInt32                                                                                      basePipelineIndex;
609                 };
610
611                 m_graphicsPipelines             = createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
612         }
613
614         // Create vertex buffer
615         {
616                 createQuad();
617                 const VkDeviceSize vertexDataSize = m_vertices.size() * sizeof(tcu::Vec4);
618                 const VkBufferCreateInfo vertexBufferParams =
619                 {
620                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
621                         DE_NULL,                                                                        // const void*                  pNext;
622                         0u,                                                                                     // VkBufferCreateFlags  flags;
623                         vertexDataSize,                                                         // VkDeviceSize                 size;
624                         VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,                      // VkBufferUsageFlags   usage;
625                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
626                         1u,                                                                                     // deUint32                             queueFamilyCount;
627                         &queueFamilyIndex                                                       // const deUint32*              pQueueFamilyIndices;
628                 };
629
630                 m_vertexBuffer          = createBuffer(vk, vkDevice, &vertexBufferParams);
631                 m_vertexBufferAlloc     = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_vertexBuffer), MemoryRequirement::HostVisible);
632
633                 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_vertexBuffer, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset()));
634
635                 // Load vertices into vertex buffer
636                 deMemcpy(m_vertexBufferAlloc->getHostPtr(), m_vertices.data(), (size_t)vertexDataSize);
637                 flushMappedMemoryRange(vk, vkDevice, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset(), vertexDataSize);
638         }
639
640         // Create command pool
641         {
642                 const VkCommandPoolCreateInfo cmdPoolParams =
643                 {
644                         VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,             // VkStructureType              sType;
645                         DE_NULL,                                                                                // const void*                  pNext;
646                         VK_COMMAND_POOL_CREATE_TRANSIENT_BIT,                   // VkCmdPoolCreateFlags flags;
647                         queueFamilyIndex,                                                               // deUint32                             queueFamilyIndex;
648                 };
649
650                 m_cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
651         }
652
653         // Create command buffer
654         {
655                 const VkCommandBufferAllocateInfo cmdBufferParams =
656                 {
657                         VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType                      sType;
658                         DE_NULL,                                                                                // const void*                          pNext;
659                         *m_cmdPool,                                                                             // VkCmdPool                            cmdPool;
660                         VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                // VkCmdBufferLevel                     level;
661                         1u                                                                                              // deUint32                                     count;
662                 };
663
664                 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
665                 {
666                         VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,    // VkStructureType                      sType;
667                         DE_NULL,                                                                                // const void*                          pNext;
668                         0u,                                                                                             // VkCmdBufferOptimizeFlags     flags;
669                         (const VkCommandBufferInheritanceInfo*)DE_NULL,
670                 };
671
672                 const VkClearValue clearValue = makeClearValueColorF32(0.0, 0.0, 0.0, 0.0);
673
674                 const VkClearValue attachmentClearValues[1] =
675                 {
676                         clearValue,
677                 };
678
679                 const VkRenderPassBeginInfo renderPassBeginInfo =
680                 {
681                         VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,                               // VkStructureType              sType;
682                         DE_NULL,                                                                                                // const void*                  pNext;
683                         *m_renderPass,                                                                                  // VkRenderPass                 renderPass;
684                         *m_framebuffer,                                                                                 // VkFramebuffer                framebuffer;
685                         {
686                                 { 0, 0 },
687                                 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() }
688                         },                                                                                                              // VkRect2D                             renderArea;
689                         1u,                                                                                                             // deUint32                             clearValueCount;
690                         attachmentClearValues                                                                   // const VkClearValue*  pClearValues;
691                 };
692
693                 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferParams);
694
695                 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
696
697                 const VkImageMemoryBarrier initialImageBarrier =
698                 {
699                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
700                         DE_NULL,                                                                        // const void*                          pNext;
701                         0,                                                                                      // VkMemoryOutputFlags          outputMask;
702                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,           // VkMemoryInputFlags           inputMask;
703                         VK_IMAGE_LAYOUT_UNDEFINED,                                      // VkImageLayout                        oldLayout;
704                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // VkImageLayout                        newLayout;
705                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
706                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     destQueueFamilyIndex;
707                         *m_colorImage,                                                          // VkImage                                      image;
708                         {                                                                                       // VkImageSubresourceRange      subresourceRange;
709                                 VK_IMAGE_ASPECT_COLOR_BIT,                              // VkImageAspectFlags   aspectMask;
710                                 0u,                                                                             // deUint32                             baseMipLevel;
711                                 1u,                                                                             // deUint32                             mipLevels;
712                                 0u,                                                                             // deUint32                             baseArraySlice;
713                                 1u                                                                              // deUint32                             arraySize;
714                         }
715                 };
716
717                 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &initialImageBarrier);
718
719                 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
720
721                 const VkDeviceSize      vertexBufferOffset[1] = { 0 };
722
723                 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_graphicsPipelines);
724                 vk.cmdBindDescriptorSets(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0u, 1, &*m_descriptorSet, 0u, DE_NULL);
725                 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &m_vertexBuffer.get(), vertexBufferOffset);
726                 vk.cmdDraw(*m_cmdBuffer, (deUint32)m_vertices.size(), 1, 0, 0);
727                 vk.cmdEndRenderPass(*m_cmdBuffer);
728
729                 const VkImageMemoryBarrier imageBarrier =
730                 {
731                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
732                         DE_NULL,                                                                        // const void*                          pNext;
733                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,           // VkMemoryOutputFlags          outputMask;
734                         VK_ACCESS_TRANSFER_READ_BIT,                            // VkMemoryInputFlags           inputMask;
735                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // VkImageLayout                        oldLayout;
736                         VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,           // VkImageLayout                        newLayout;
737                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
738                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     destQueueFamilyIndex;
739                         *m_colorImage,                                                          // VkImage                                      image;
740                         {                                                                                       // VkImageSubresourceRange      subresourceRange;
741                                 VK_IMAGE_ASPECT_COLOR_BIT,                              // VkImageAspectFlags   aspectMask;
742                                 0u,                                                                             // deUint32                             baseMipLevel;
743                                 1u,                                                                             // deUint32                             mipLevels;
744                                 0u,                                                                             // deUint32                             baseArraySlice;
745                                 1u                                                                              // deUint32                             arraySize;
746                         }
747                 };
748
749                 const VkBufferMemoryBarrier bufferBarrier =
750                 {
751                         VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType              sType;
752                         DE_NULL,                                                                        // const void*                  pNext;
753                         VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkMemoryOutputFlags  outputMask;
754                         VK_ACCESS_HOST_READ_BIT,                                        // VkMemoryInputFlags   inputMask;
755                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                             srcQueueFamilyIndex;
756                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                             destQueueFamilyIndex;
757                         *m_resultBuffer,                                                        // VkBuffer                             buffer;
758                         0u,                                                                                     // VkDeviceSize                 offset;
759                         m_pixelDataSize                                                         // VkDeviceSize                 size;
760                 };
761
762                 const VkBufferImageCopy copyRegion =
763                 {
764                         0u,                                                                                     // VkDeviceSize                         bufferOffset;
765                         (deUint32)m_renderSize.x(),                                     // deUint32                                     bufferRowLength;
766                         (deUint32)m_renderSize.y(),                                     // deUint32                                     bufferImageHeight;
767                         { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u },      // VkImageSubresourceCopy       imageSubresource;
768                         { 0, 0, 0 },                                                            // VkOffset3D                           imageOffset;
769                         {
770                                 (deUint32)m_renderSize.x(),
771                                 (deUint32)m_renderSize.y(),
772                                 1u
773                         }                                                                                       // VkExtent3D                           imageExtent;
774                 };
775
776                 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &imageBarrier);
777                 vk.cmdCopyImageToBuffer(*m_cmdBuffer, *m_colorImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *m_resultBuffer, 1, &copyRegion);
778                 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &bufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
779
780                 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
781         }
782
783         // Create fence
784         {
785                 const VkFenceCreateInfo fenceParams =
786                 {
787                         VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,    // VkStructureType              sType;
788                         DE_NULL,                                                                // const void*                  pNext;
789                         0u                                                                              // VkFenceCreateFlags   flags;
790                 };
791
792                 m_fence = createFence(vk, vkDevice, &fenceParams);
793         }
794 }
795
796 tcu::TestStatus BufferViewTestInstance::checkResult (deInt8 factor)
797 {
798         const DeviceInterface&                  vk                                      = m_context.getDeviceInterface();
799         const VkDevice                                  vkDevice                        = m_context.getDevice();
800         const tcu::TextureFormat                tcuFormat                       = mapVkFormat(m_colorFormat);
801         de::MovePtr<tcu::TextureLevel>  resultLevel                     (new tcu::TextureLevel(tcuFormat, m_renderSize.x(), m_renderSize.y()));
802
803         invalidateMappedMemoryRange(vk, vkDevice, m_resultBufferAlloc->getMemory(), m_resultBufferAlloc->getOffset(), m_pixelDataSize);
804         tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), m_resultBufferAlloc->getHostPtr()));
805
806         tcu::ConstPixelBufferAccess pixelBuffer = resultLevel->getAccess();
807         for (deInt32 i = 0; i < (deInt32) m_renderSize.x(); ++i)
808         {
809                 tcu::IVec4 pixel        = pixelBuffer.getPixelInt(i, i);
810                 deInt32 expected        = factor * (m_testCase.elementOffset + i);
811                 deInt32 actual          = pixel[0];
812                 if (expected != actual)
813                 {
814                         std::ostringstream errorMessage;
815                         errorMessage << "BufferView test failed. expected: " << expected << " actual: " << actual;
816                         return tcu::TestStatus::fail(errorMessage.str());
817                 }
818         }
819
820         return tcu::TestStatus::pass("BufferView test");
821 }
822
823 tcu::TestStatus BufferViewTestInstance::iterate (void)
824 {
825         const DeviceInterface&          vk                      = m_context.getDeviceInterface();
826         const VkDevice                          vkDevice        = m_context.getDevice();
827         const VkQueue                           queue           = m_context.getUniversalQueue();
828         const VkSubmitInfo                      submitInfo      =
829         {
830                 VK_STRUCTURE_TYPE_SUBMIT_INFO,
831                 DE_NULL,
832                 0u,
833                 (const VkSemaphore*)DE_NULL,
834                 (const VkPipelineStageFlags*)DE_NULL,
835                 1u,
836                 &m_cmdBuffer.get(),
837                 0u,
838                 (const VkSemaphore*)DE_NULL,
839         };
840
841         VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
842         VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
843         VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
844
845         tcu::TestStatus                         testStatus      = checkResult();
846         if (testStatus.getCode() != QP_TEST_RESULT_PASS)
847         {
848                 return testStatus;
849         }
850
851         // Generate and bind another buffer
852         std::vector<deUint32>           uniformData;
853         const VkDeviceSize                      uniformSize = m_testCase.bufferSize * sizeof(deUint32);
854         const deInt8                            factor          = 2;
855
856         generateBuffer(uniformData, m_testCase.bufferSize, factor);
857         deMemcpy(m_uniformBufferAlloc->getHostPtr(), uniformData.data(), (size_t)uniformSize);
858
859         VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
860         VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
861         VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
862
863         return checkResult(factor);
864 }
865
866 class BufferViewTestCase : public vkt::TestCase
867 {
868 public:
869                                                         BufferViewTestCase                      (tcu::TestContext&                      testCtx,
870                                                                                                                  const std::string&                     name,
871                                                                                                                  const std::string&                     description,
872                                                                                                                  BufferViewCaseParams   bufferViewTestInfo)
873                                                                 : vkt::TestCase                 (testCtx, name, description)
874                                                                 , m_bufferViewTestInfo  (bufferViewTestInfo)
875                                                         {}
876
877         virtual                                 ~BufferViewTestCase                     (void) {}
878         virtual void                    initPrograms                            (SourceCollections&                     programCollection) const;
879
880         virtual TestInstance*   createInstance                          (Context&                                       context) const
881                                                         {
882                                                                 return new BufferViewTestInstance(context, m_bufferViewTestInfo);
883                                                         }
884 private:
885         BufferViewCaseParams    m_bufferViewTestInfo;
886 };
887
888 void BufferViewTestCase::initPrograms (SourceCollections& programCollection) const
889 {
890         programCollection.glslSources.add("vert") << glu::VertexSource(
891                 "#version 310 es\n"
892                 "layout (location = 0) in highp vec4 a_position;\n"
893                 "void main()\n"
894                 "{\n"
895                 "       gl_Position = a_position;\n"
896                 "}\n");
897
898
899         programCollection.glslSources.add("frag") << glu::FragmentSource(
900                 "#version 310 es\n"
901                 "#extension GL_EXT_texture_buffer : enable\n"
902                 "layout (set=0, binding=0) uniform highp usamplerBuffer u_buffer;\n"
903                 "layout (location = 0) out highp uint o_color;\n"
904                 "void main()\n"
905                 "{\n"
906                 "       o_color = texelFetch(u_buffer, int(gl_FragCoord.x)).x;\n"
907                 "}\n");
908 }
909
910 } // anonymous
911
912 tcu::TestCaseGroup* createBufferViewAccessTests (tcu::TestContext& testCtx)
913 {
914         de::MovePtr<tcu::TestCaseGroup> bufferViewTests (new tcu::TestCaseGroup(testCtx, "access", "BufferView Access Tests"));
915
916         {
917                 BufferViewCaseParams info =
918                 {
919                         512,    // deUint32     bufferSize
920                         512,    // deUint32     bufferViewSize
921                         0,              // deUint32     elementOffset
922                 };
923                 std::ostringstream description;
924                 description << "bufferSize: " << info.bufferSize << " bufferViewSize: " << info.bufferViewSize << " bufferView element offset: " << info.elementOffset;
925                 bufferViewTests->addChild(new BufferViewTestCase(testCtx, "buffer_view_memory_test_complete", description.str(), info));
926         }
927
928         {
929                 BufferViewCaseParams info =
930                 {
931                         4096,   // deUint32     bufferSize
932                         512,    // deUint32     bufferViewSize
933                         0,              // deUint32     elementOffset
934                 };
935                 std::ostringstream description;
936                 description << "bufferSize: " << info.bufferSize << " bufferViewSize: " << info.bufferViewSize << " bufferView element offset: " << info.elementOffset;
937                 bufferViewTests->addChild(new BufferViewTestCase(testCtx, "buffer_view_memory_test_partial_offset0", description.str(), info));
938         }
939
940         {
941                 BufferViewCaseParams info =
942                 {
943                         4096,   // deUint32     bufferSize
944                         512,    // deUint32     bufferViewSize
945                         128,    // deUint32     elementOffset
946                 };
947                 std::ostringstream description;
948                 description << "bufferSize: " << info.bufferSize << " bufferViewSize: " << info.bufferViewSize << " bufferView element offset: " << info.elementOffset;
949                 bufferViewTests->addChild(new BufferViewTestCase(testCtx, "buffer_view_memory_test_partial_offset1", description.str(), info));
950         }
951
952         return bufferViewTests.release();
953 }
954
955 } // api
956 } // vkt