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