Add new framebuffer fetch extension tests am: 2a609fb223
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / api / vktApiBufferAndImageAllocationUtil.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2017 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Implementation of utility classes for various kinds of
22  * allocation memory for buffers and images
23  *//*--------------------------------------------------------------------*/
24
25 #include "vktApiBufferAndImageAllocationUtil.hpp"
26
27 #include "deInt32.h"
28 #include "tcuVectorUtil.hpp"
29 #include "vkQueryUtil.hpp"
30 #include "vkMemUtil.hpp"
31 #include "vkRefUtil.hpp"
32
33 #include <sstream>
34
35 namespace vkt
36 {
37
38 namespace api
39 {
40
41 void BufferSuballocation::createTestBuffer                                                              (VkDeviceSize                           size,
42                                                                                                                                                  VkBufferUsageFlags                     usage,
43                                                                                                                                                  Context&                                       context,
44                                                                                                                                                  Allocator&                                     allocator,
45                                                                                                                                                  Move<VkBuffer>&                        buffer,
46                                                                                                                                                  const MemoryRequirement&       requirement,
47                                                                                                                                                  de::MovePtr<Allocation>&       memory) const
48 {
49         const VkDevice                                          vkDevice                                                = context.getDevice();
50         const DeviceInterface&                          vk                                                              = context.getDeviceInterface();
51         const deUint32                                          queueFamilyIndex                                = context.getUniversalQueueFamilyIndex();
52         const VkBufferCreateInfo                        bufferParams                                    =
53         {
54                 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,                                                   //      VkStructureType                 sType;
55                 DE_NULL,                                                                                                                //      const void*                             pNext;
56                 0u,                                                                                                                             //      VkBufferCreateFlags             flags;
57                 size,                                                                                                                   //      VkDeviceSize                    size;
58                 usage,                                                                                                                  //      VkBufferUsageFlags              usage;
59                 VK_SHARING_MODE_EXCLUSIVE,                                                                              //      VkSharingMode                   sharingMode;
60                 1u,                                                                                                                             //      deUint32                                queueFamilyCount;
61                 &queueFamilyIndex,                                                                                              //      const deUint32*                 pQueueFamilyIndices;
62         };
63
64         buffer = vk::createBuffer(vk, vkDevice, &bufferParams, (const VkAllocationCallbacks*)DE_NULL);
65         memory = allocator.allocate(getBufferMemoryRequirements(vk, vkDevice, *buffer), requirement);
66         VK_CHECK(vk.bindBufferMemory(vkDevice, *buffer, memory->getMemory(), 0));
67 }
68
69 void BufferDedicatedAllocation::createTestBuffer                                                (VkDeviceSize                           size,
70                                                                                                                                                  VkBufferUsageFlags                     usage,
71                                                                                                                                                  Context&                                       context,
72                                                                                                                                                  Allocator&                                     allocator,
73                                                                                                                                                  Move<VkBuffer>&                        buffer,
74                                                                                                                                                  const MemoryRequirement&       requirement,
75                                                                                                                                                  de::MovePtr<Allocation>&       memory) const
76 {
77         DE_UNREF(allocator);
78         const std::vector<std::string>& extensions                                                      = context.getDeviceExtensions();
79         const deBool                                    isSupported                                                     = std::find(extensions.begin(), extensions.end(), "VK_KHR_dedicated_allocation") != extensions.end();
80         if (!isSupported)
81         {
82                 TCU_THROW(NotSupportedError, "Not supported");
83         }
84
85         const InstanceInterface&                        vkInstance                                              = context.getInstanceInterface();
86         const VkDevice                                          vkDevice                                                = context.getDevice();
87         const VkPhysicalDevice                          vkPhysicalDevice                                = context.getPhysicalDevice();
88         const DeviceInterface&                          vk                                                              = context.getDeviceInterface();
89         const deUint32                                          queueFamilyIndex                                = context.getUniversalQueueFamilyIndex();
90
91         const VkBufferCreateInfo                        bufferParams                                    =
92         {
93                 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,                                                   //      VkStructureType                 sType;
94                 DE_NULL,                                                                                                                //      const void*                             pNext;
95                 0u,                                                                                                                             //      VkBufferCreateFlags             flags;
96                 size,                                                                                                                   //      VkDeviceSize                    size;
97                 usage,                                                                                                                  //      VkBufferUsageFlags              usage;
98                 VK_SHARING_MODE_EXCLUSIVE,                                                                              //      VkSharingMode                   sharingMode;
99                 1u,                                                                                                                             //      deUint32                                queueFamilyCount;
100                 &queueFamilyIndex,                                                                                              //      const deUint32*                 pQueueFamilyIndices;
101         };
102
103         buffer = vk::createBuffer(vk, vkDevice, &bufferParams, (const VkAllocationCallbacks*)DE_NULL);
104         memory = allocateDedicated(vkInstance, vk, vkPhysicalDevice, vkDevice, buffer.get(), requirement);
105         VK_CHECK(vk.bindBufferMemory(vkDevice, *buffer, memory->getMemory(), memory->getOffset()));
106 }
107
108 void ImageSuballocation::createTestImage                                                                (tcu::IVec2                                     size,
109                                                                                                                                                  VkFormat                                       format,
110                                                                                                                                                  Context&                                       context,
111                                                                                                                                                  Allocator&                                     allocator,
112                                                                                                                                                  Move<VkImage>&                         image,
113                                                                                                                                                  const MemoryRequirement&       requirement,
114                                                                                                                                                  de::MovePtr<Allocation>&       memory) const
115 {
116         const VkDevice                                          vkDevice                                                = context.getDevice();
117         const DeviceInterface&                          vk                                                              = context.getDeviceInterface();
118         const deUint32                                          queueFamilyIndex                                = context.getUniversalQueueFamilyIndex();
119
120         const VkImageCreateInfo                         colorImageParams                                =
121         {
122                 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                    // VkStructureType                      sType;
123                 DE_NULL,                                                                                                                // const void*                          pNext;
124                 0u,                                                                                                                             // VkImageCreateFlags           flags;
125                 VK_IMAGE_TYPE_2D,                                                                                               // VkImageType                          imageType;
126                 format,                                                                                                                 // VkFormat                                     format;
127                 { (deUint32)size.x(), (deUint32)size.y(), 1u },                                 // VkExtent3D                           extent;
128                 1u,                                                                                                                             // deUint32                                     mipLevels;
129                 1u,                                                                                                                             // deUint32                                     arraySize;
130                 VK_SAMPLE_COUNT_1_BIT,                                                                                  // deUint32                                     samples;
131                 VK_IMAGE_TILING_OPTIMAL,                                                                                // VkImageTiling                        tiling;
132                 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags     usage;
133                 VK_SHARING_MODE_EXCLUSIVE,                                                                              // VkSharingMode                        sharingMode;
134                 1u,                                                                                                                             // deUint32                                     queueFamilyCount;
135                 &queueFamilyIndex,                                                                                              // const deUint32*                      pQueueFamilyIndices;
136                 VK_IMAGE_LAYOUT_UNDEFINED,                                                                              // VkImageLayout                        initialLayout;
137         };
138
139         image = createImage(vk, vkDevice, &colorImageParams);
140         memory = allocator.allocate(getImageMemoryRequirements(vk, vkDevice, *image), requirement);
141         VK_CHECK(vk.bindImageMemory(vkDevice, *image, memory->getMemory(), memory->getOffset()));
142 }
143
144 void ImageDedicatedAllocation::createTestImage                                                  (tcu::IVec2                                     size,
145                                                                                                                                                  VkFormat                                       format,
146                                                                                                                                                  Context&                                       context,
147                                                                                                                                                  Allocator&                                     allocator,
148                                                                                                                                                  Move<VkImage>&                         image,
149                                                                                                                                                  const MemoryRequirement&       requirement,
150                                                                                                                                                  de::MovePtr<Allocation>&       memory) const
151 {
152         DE_UNREF(allocator);
153         const std::vector<std::string>&         extensions                                              = context.getDeviceExtensions();
154         const deBool                                            isSupported                                             = std::find(extensions.begin(), extensions.end(), "VK_KHR_dedicated_allocation") != extensions.end();
155         if (!isSupported)
156         {
157                 TCU_THROW(NotSupportedError, "Not supported");
158         }
159
160         const InstanceInterface&                        vkInstance                                              = context.getInstanceInterface();
161         const VkDevice                                          vkDevice                                                = context.getDevice();
162         const VkPhysicalDevice                          vkPhysicalDevice                                = context.getPhysicalDevice();
163         const DeviceInterface&                          vk                                                              = context.getDeviceInterface();
164         const deUint32                                          queueFamilyIndex                                = context.getUniversalQueueFamilyIndex();
165
166         const VkImageCreateInfo                         colorImageParams                                =
167         {
168                 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                    // VkStructureType                      sType;
169                 DE_NULL,                                                                                                                // const void*                          pNext;
170                 0u,                                                                                                                             // VkImageCreateFlags           flags;
171                 VK_IMAGE_TYPE_2D,                                                                                               // VkImageType                          imageType;
172                 format,                                                                                                                 // VkFormat                                     format;
173                 { (deUint32)size.x(), (deUint32)size.y(), 1u },                                 // VkExtent3D                           extent;
174                 1u,                                                                                                                             // deUint32                                     mipLevels;
175                 1u,                                                                                                                             // deUint32                                     arraySize;
176                 VK_SAMPLE_COUNT_1_BIT,                                                                                  // deUint32                                     samples;
177                 VK_IMAGE_TILING_OPTIMAL,                                                                                // VkImageTiling                        tiling;
178                 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags     usage;
179                 VK_SHARING_MODE_EXCLUSIVE,                                                                              // VkSharingMode                        sharingMode;
180                 1u,                                                                                                                             // deUint32                                     queueFamilyCount;
181                 &queueFamilyIndex,                                                                                              // const deUint32*                      pQueueFamilyIndices;
182                 VK_IMAGE_LAYOUT_UNDEFINED,                                                                              // VkImageLayout                        initialLayout;
183         };
184
185         image = createImage(vk, vkDevice, &colorImageParams);
186         memory = allocateDedicated(vkInstance, vk, vkPhysicalDevice, vkDevice, image.get(), requirement);
187         VK_CHECK(vk.bindImageMemory(vkDevice, *image, memory->getMemory(), memory->getOffset()));
188 }
189
190 } // api
191 } // vkt