1 #ifndef _VKTDRAWIMAGEOBJECTUTIL_HPP 2 #define _VKTDRAWIMAGEOBJECTUTIL_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2015 The Khronos Group Inc. 8 * Copyright (c) 2015 Intel Corporation 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 *//*! 23 * \file 24 * \brief Image Object Util 25 *//*--------------------------------------------------------------------*/ 26 27 #include "vkDefs.hpp" 28 #include "vkMemUtil.hpp" 29 #include "vkRefUtil.hpp" 30 31 #include "deSharedPtr.hpp" 32 33 #include "tcuTexture.hpp" 34 35 namespace vkt 36 { 37 namespace Draw 38 { 39 40 class MemoryOp 41 { 42 public: 43 static void pack (int pixelSize, 44 int width, 45 int height, 46 int depth, 47 vk::VkDeviceSize rowPitchOrZero, 48 vk::VkDeviceSize depthPitchOrZero, 49 const void * srcBuffer, 50 void * destBuffer); 51 52 static void unpack (int pixelSize, 53 int width, 54 int height, 55 int depth, 56 vk::VkDeviceSize rowPitchOrZero, 57 vk::VkDeviceSize depthPitchOrZero, 58 const void * srcBuffer, 59 void * destBuffer); 60 }; 61 62 class Image 63 { 64 public: 65 static de::SharedPtr<Image> create (const vk::DeviceInterface& vk, vk::VkDevice device, const vk::VkImageCreateInfo& createInfo, deUint32 queueFamilyIndex); 66 67 static de::SharedPtr<Image> createAndAlloc (const vk::DeviceInterface& vk, 68 vk::VkDevice device, 69 const vk::VkImageCreateInfo& createInfo, 70 vk::Allocator& allocator, 71 deUint32 queueFamilyIndex, 72 vk::MemoryRequirement memoryRequirement = vk::MemoryRequirement::Any); 73 74 tcu::ConstPixelBufferAccess readSurface (vk::VkQueue queue, 75 vk::Allocator& allocator, 76 vk::VkImageLayout layout, 77 vk::VkOffset3D offset, 78 int width, 79 int height, 80 vk::VkImageAspectFlagBits aspect, 81 unsigned int mipLevel = 0, 82 unsigned int arrayElement = 0); 83 84 tcu::ConstPixelBufferAccess readSurface1D (vk::VkQueue queue, 85 vk::Allocator& allocator, 86 vk::VkImageLayout layout, 87 vk::VkOffset3D offset, 88 int width, 89 vk::VkImageAspectFlagBits aspect, 90 unsigned int mipLevel = 0, 91 unsigned int arrayElement = 0); 92 93 tcu::ConstPixelBufferAccess readVolume (vk::VkQueue queue, 94 vk::Allocator& allocator, 95 vk::VkImageLayout layout, 96 vk::VkOffset3D offset, 97 int width, 98 int height, 99 int depth, 100 vk::VkImageAspectFlagBits aspect, 101 unsigned int mipLevel = 0, 102 unsigned int arrayElement = 0); 103 104 tcu::ConstPixelBufferAccess readSurfaceLinear (vk::VkOffset3D offset, 105 int width, 106 int height, 107 int depth, 108 vk::VkImageAspectFlagBits aspect, 109 unsigned int mipLevel = 0, 110 unsigned int arrayElement = 0); 111 112 void read (vk::VkQueue queue, 113 vk::Allocator& allocator, 114 vk::VkImageLayout layout, 115 vk::VkOffset3D offset, 116 int width, 117 int height, 118 int depth, 119 unsigned int mipLevel, 120 unsigned int arrayElement, 121 vk::VkImageAspectFlagBits aspect, 122 vk::VkImageType type, 123 void * data); 124 125 void readUsingBuffer (vk::VkQueue queue, 126 vk::Allocator& allocator, 127 vk::VkImageLayout layout, 128 vk::VkOffset3D offset, 129 int width, 130 int height, 131 int depth, 132 unsigned int mipLevel, 133 unsigned int arrayElement, 134 vk::VkImageAspectFlagBits aspect, 135 void * data); 136 137 void readLinear (vk::VkOffset3D offset, 138 int width, 139 int height, 140 int depth, 141 unsigned int mipLevel, 142 unsigned int arrayElement, 143 vk::VkImageAspectFlagBits aspect, 144 void * data); 145 146 void uploadVolume (const tcu::ConstPixelBufferAccess& access, 147 vk::VkQueue queue, 148 vk::Allocator& allocator, 149 vk::VkImageLayout layout, 150 vk::VkOffset3D offset, 151 vk::VkImageAspectFlagBits aspect, 152 unsigned int mipLevel = 0, 153 unsigned int arrayElement = 0); 154 155 void uploadSurface (const tcu::ConstPixelBufferAccess& access, 156 vk::VkQueue queue, 157 vk::Allocator& allocator, 158 vk::VkImageLayout layout, 159 vk::VkOffset3D offset, 160 vk::VkImageAspectFlagBits aspect, 161 unsigned int mipLevel = 0, 162 unsigned int arrayElement = 0); 163 164 void uploadSurface1D (const tcu::ConstPixelBufferAccess& access, 165 vk::VkQueue queue, 166 vk::Allocator& allocator, 167 vk::VkImageLayout layout, 168 vk::VkOffset3D offset, 169 vk::VkImageAspectFlagBits aspect, 170 unsigned int mipLevel = 0, 171 unsigned int arrayElement = 0); 172 173 void uploadSurfaceLinear (const tcu::ConstPixelBufferAccess& access, 174 vk::VkOffset3D offset, 175 int width, 176 int height, 177 int depth, 178 vk::VkImageAspectFlagBits aspect, 179 unsigned int mipLevel = 0, 180 unsigned int arrayElement = 0); 181 182 void upload (vk::VkQueue queue, 183 vk::Allocator& allocator, 184 vk::VkImageLayout layout, 185 vk::VkOffset3D offset, 186 int width, 187 int height, 188 int depth, 189 unsigned int mipLevel, 190 unsigned int arrayElement, 191 vk::VkImageAspectFlagBits aspect, 192 vk::VkImageType type, 193 const void * data); 194 195 void uploadUsingBuffer (vk::VkQueue queue, 196 vk::Allocator& allocator, 197 vk::VkImageLayout layout, 198 vk::VkOffset3D offset, 199 int width, 200 int height, 201 int depth, 202 unsigned int mipLevel, 203 unsigned int arrayElement, 204 vk::VkImageAspectFlagBits aspect, 205 const void * data); 206 207 void uploadLinear (vk::VkOffset3D offset, 208 int width, 209 int height, 210 int depth, 211 unsigned int mipLevel, 212 unsigned int arrayElement, 213 vk::VkImageAspectFlagBits aspect, 214 const void * data); 215 216 de::SharedPtr<Image> copyToLinearImage (vk::VkQueue queue, 217 vk::Allocator& allocator, 218 vk::VkImageLayout layout, 219 vk::VkOffset3D offset, 220 int width, 221 int height, 222 int depth, 223 unsigned int mipLevel, 224 unsigned int arrayElement, 225 vk::VkImageAspectFlagBits aspect, 226 vk::VkImageType type); 227 getFormat(void) const228 const vk::VkFormat& getFormat (void) const { return m_format; } object(void) const229 vk::VkImage object (void) const { return *m_object; } 230 void bindMemory (de::MovePtr<vk::Allocation> allocation); getBoundMemory(void) const231 vk::Allocation getBoundMemory (void) const { return *m_allocation; } 232 233 private: 234 Image (const vk::DeviceInterface& vk, 235 vk::VkDevice device, 236 deUint32 queueFamilyIndex, 237 vk::VkFormat format, 238 const vk::VkExtent3D& extend, 239 deUint32 levelCount, 240 deUint32 layerCount, 241 vk::Move<vk::VkImage> object); 242 243 Image (const Image& other); // Not allowed! 244 Image& operator= (const Image& other); // Not allowed! 245 246 de::MovePtr<vk::Allocation> m_allocation; 247 vk::Unique<vk::VkImage> m_object; 248 249 deUint32 m_queueFamilyIndex; 250 251 vk::VkFormat m_format; 252 vk::VkExtent3D m_extent; 253 deUint32 m_levelCount; 254 deUint32 m_layerCount; 255 256 std::vector<deUint8> m_pixelAccessData; 257 258 const vk::DeviceInterface& m_vk; 259 vk::VkDevice m_device; 260 }; 261 262 void transition2DImage (const vk::DeviceInterface& vk, 263 vk::VkCommandBuffer cmdBuffer, 264 vk::VkImage image, 265 vk::VkImageAspectFlags aspectMask, 266 vk::VkImageLayout oldLayout, 267 vk::VkImageLayout newLayout, 268 vk::VkAccessFlags srcAccessMask, 269 vk::VkAccessFlags dstAccessMask, 270 vk::VkPipelineStageFlags srcStageMask, 271 vk::VkPipelineStageFlags dstStageMask); 272 273 void initialTransitionColor2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout, 274 vk::VkAccessFlags dstAccessMask, vk::VkPipelineStageFlags dstStageMask); 275 276 void initialTransitionDepth2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout, 277 vk::VkAccessFlags dstAccessMask, vk::VkPipelineStageFlags dstStageMask); 278 279 void initialTransitionStencil2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout, 280 vk::VkAccessFlags dstAccessMask, vk::VkPipelineStageFlags dstStageMask); 281 282 void initialTransitionDepthStencil2DImage (const vk::DeviceInterface& vk, 283 vk::VkCommandBuffer cmdBuffer, 284 vk::VkImage image, 285 vk::VkImageLayout layout, 286 vk::VkAccessFlags dstAccessMask, 287 vk::VkPipelineStageFlags dstStageMask); 288 289 } // Draw 290 } // vkt 291 292 #endif // _VKTDRAWIMAGEOBJECTUTIL_HPP 293