vktDrawImageObjectUtil.hpp revision 5e1fb53c166f5145e8a68aa96da9d16fcde7a30d
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 35namespace vkt 36{ 37namespace Draw 38{ 39 40class MemoryOp 41{ 42public: 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 62class Image 63{ 64public: 65 static de::SharedPtr<Image> create (const vk::DeviceInterface& vk, vk::VkDevice device, const vk::VkImageCreateInfo& createInfo); 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 vk::MemoryRequirement memoryRequirement = vk::MemoryRequirement::Any); 72 73 tcu::ConstPixelBufferAccess readSurface (vk::VkQueue queue, 74 vk::Allocator& allocator, 75 vk::VkImageLayout layout, 76 vk::VkOffset3D offset, 77 int width, 78 int height, 79 vk::VkImageAspectFlagBits aspect, 80 unsigned int mipLevel = 0, 81 unsigned int arrayElement = 0); 82 83 tcu::ConstPixelBufferAccess readSurface1D (vk::VkQueue queue, 84 vk::Allocator& allocator, 85 vk::VkImageLayout layout, 86 vk::VkOffset3D offset, 87 int width, 88 vk::VkImageAspectFlagBits aspect, 89 unsigned int mipLevel = 0, 90 unsigned int arrayElement = 0); 91 92 tcu::ConstPixelBufferAccess readVolume (vk::VkQueue queue, 93 vk::Allocator& allocator, 94 vk::VkImageLayout layout, 95 vk::VkOffset3D offset, 96 int width, 97 int height, 98 int depth, 99 vk::VkImageAspectFlagBits aspect, 100 unsigned int mipLevel = 0, 101 unsigned int arrayElement = 0); 102 103 tcu::ConstPixelBufferAccess readSurfaceLinear (vk::VkOffset3D offset, 104 int width, 105 int height, 106 int depth, 107 vk::VkImageAspectFlagBits aspect, 108 unsigned int mipLevel = 0, 109 unsigned int arrayElement = 0); 110 111 void read (vk::VkQueue queue, 112 vk::Allocator& allocator, 113 vk::VkImageLayout layout, 114 vk::VkOffset3D offset, 115 int width, 116 int height, 117 int depth, 118 unsigned int mipLevel, 119 unsigned int arrayElement, 120 vk::VkImageAspectFlagBits aspect, 121 vk::VkImageType type, 122 void * data); 123 124 void readUsingBuffer (vk::VkQueue queue, 125 vk::Allocator& allocator, 126 vk::VkImageLayout layout, 127 vk::VkOffset3D offset, 128 int width, 129 int height, 130 int depth, 131 unsigned int mipLevel, 132 unsigned int arrayElement, 133 vk::VkImageAspectFlagBits aspect, 134 void * data); 135 136 void readLinear (vk::VkOffset3D offset, 137 int width, 138 int height, 139 int depth, 140 unsigned int mipLevel, 141 unsigned int arrayElement, 142 vk::VkImageAspectFlagBits aspect, 143 void * data); 144 145 void uploadVolume (const tcu::ConstPixelBufferAccess& access, 146 vk::VkQueue queue, 147 vk::Allocator& allocator, 148 vk::VkImageLayout layout, 149 vk::VkOffset3D offset, 150 vk::VkImageAspectFlagBits aspect, 151 unsigned int mipLevel = 0, 152 unsigned int arrayElement = 0); 153 154 void uploadSurface (const tcu::ConstPixelBufferAccess& access, 155 vk::VkQueue queue, 156 vk::Allocator& allocator, 157 vk::VkImageLayout layout, 158 vk::VkOffset3D offset, 159 vk::VkImageAspectFlagBits aspect, 160 unsigned int mipLevel = 0, 161 unsigned int arrayElement = 0); 162 163 void uploadSurface1D (const tcu::ConstPixelBufferAccess& access, 164 vk::VkQueue queue, 165 vk::Allocator& allocator, 166 vk::VkImageLayout layout, 167 vk::VkOffset3D offset, 168 vk::VkImageAspectFlagBits aspect, 169 unsigned int mipLevel = 0, 170 unsigned int arrayElement = 0); 171 172 void uploadSurfaceLinear (const tcu::ConstPixelBufferAccess& access, 173 vk::VkOffset3D offset, 174 int width, 175 int height, 176 int depth, 177 vk::VkImageAspectFlagBits aspect, 178 unsigned int mipLevel = 0, 179 unsigned int arrayElement = 0); 180 181 void upload (vk::VkQueue queue, 182 vk::Allocator& allocator, 183 vk::VkImageLayout layout, 184 vk::VkOffset3D offset, 185 int width, 186 int height, 187 int depth, 188 unsigned int mipLevel, 189 unsigned int arrayElement, 190 vk::VkImageAspectFlagBits aspect, 191 vk::VkImageType type, 192 const void * data); 193 194 void uploadUsingBuffer (vk::VkQueue queue, 195 vk::Allocator& allocator, 196 vk::VkImageLayout layout, 197 vk::VkOffset3D offset, 198 int width, 199 int height, 200 int depth, 201 unsigned int mipLevel, 202 unsigned int arrayElement, 203 vk::VkImageAspectFlagBits aspect, 204 const void * data); 205 206 void uploadLinear (vk::VkOffset3D offset, 207 int width, 208 int height, 209 int depth, 210 unsigned int mipLevel, 211 unsigned int arrayElement, 212 vk::VkImageAspectFlagBits aspect, 213 const void * data); 214 215 de::SharedPtr<Image> copyToLinearImage (vk::VkQueue queue, 216 vk::Allocator& allocator, 217 vk::VkImageLayout layout, 218 vk::VkOffset3D offset, 219 int width, 220 int height, 221 int depth, 222 unsigned int mipLevel, 223 unsigned int arrayElement, 224 vk::VkImageAspectFlagBits aspect, 225 vk::VkImageType type); 226 227 const vk::VkFormat& getFormat (void) const { return m_format; } 228 vk::VkImage object (void) const { return *m_object; } 229 void bindMemory (de::MovePtr<vk::Allocation> allocation); 230 vk::Allocation getBoundMemory (void) const { return *m_allocation; } 231 232private: 233 Image (const vk::DeviceInterface& vk, 234 vk::VkDevice device, 235 vk::VkFormat format, 236 const vk::VkExtent3D& extend, 237 deUint32 levelCount, 238 deUint32 layerCount, 239 vk::Move<vk::VkImage> object); 240 241 Image (const Image& other); // Not allowed! 242 Image& operator= (const Image& other); // Not allowed! 243 244 de::MovePtr<vk::Allocation> m_allocation; 245 vk::Unique<vk::VkImage> m_object; 246 247 vk::VkFormat m_format; 248 vk::VkExtent3D m_extent; 249 deUint32 m_levelCount; 250 deUint32 m_layerCount; 251 252 std::vector<deUint8> m_pixelAccessData; 253 254 const vk::DeviceInterface& m_vk; 255 vk::VkDevice m_device; 256}; 257 258void transition2DImage (const vk::DeviceInterface& vk, 259 vk::VkCommandBuffer cmdBuffer, 260 vk::VkImage image, 261 vk::VkImageAspectFlags aspectMask, 262 vk::VkImageLayout oldLayout, 263 vk::VkImageLayout newLayout, 264 vk::VkAccessFlags srcAccessMask = 0, 265 vk::VkAccessFlags dstAccessMask = 0); 266 267void initialTransitionColor2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout); 268 269void initialTransitionDepth2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout); 270 271void initialTransitionStencil2DImage (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, vk::VkImageLayout layout); 272 273void initialTransitionDepthStencil2DImage (const vk::DeviceInterface& vk, 274 vk::VkCommandBuffer cmdBuffer, 275 vk::VkImage image, 276 vk::VkImageLayout layout, 277 vk::VkAccessFlags srcAccessMask = 0, 278 vk::VkAccessFlags dstAccessMask = 0); 279 280} // Draw 281} // vkt 282 283#endif // _VKTDRAWIMAGEOBJECTUTIL_HPP 284