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, int width, int height, int depth, vk::VkDeviceSize rowPitchOrZero, 44 vk::VkDeviceSize depthPitchOrZero, const void *srcBuffer, void *destBuffer); 45 46 static void unpack(int pixelSize, int width, int height, int depth, vk::VkDeviceSize rowPitchOrZero, 47 vk::VkDeviceSize depthPitchOrZero, const void *srcBuffer, void *destBuffer); 48 }; 49 50 class Image 51 { 52 public: 53 static de::SharedPtr<Image> create(const vk::DeviceInterface &vk, vk::VkDevice device, 54 const vk::VkImageCreateInfo &createInfo, uint32_t queueFamilyIndex); 55 56 static de::SharedPtr<Image> createAndAlloc(const vk::DeviceInterface &vk, vk::VkDevice device, 57 const vk::VkImageCreateInfo &createInfo, vk::Allocator &allocator, 58 uint32_t queueFamilyIndex, 59 vk::MemoryRequirement memoryRequirement = vk::MemoryRequirement::Any); 60 61 tcu::ConstPixelBufferAccess readSurface(vk::VkQueue queue, vk::Allocator &allocator, vk::VkImageLayout layout, 62 vk::VkOffset3D offset, int width, int height, 63 vk::VkImageAspectFlagBits aspect, unsigned int mipLevel = 0, 64 unsigned int arrayElement = 0); 65 66 tcu::ConstPixelBufferAccess readDepth(vk::VkQueue queue, vk::Allocator &allocator, vk::VkImageLayout layout, 67 vk::VkOffset3D offset, int width, int height, 68 vk::VkImageAspectFlagBits aspect, unsigned int mipLevel = 0, 69 unsigned int arrayElement = 0); 70 71 tcu::ConstPixelBufferAccess readSurface1D(vk::VkQueue queue, vk::Allocator &allocator, vk::VkImageLayout layout, 72 vk::VkOffset3D offset, int width, vk::VkImageAspectFlagBits aspect, 73 unsigned int mipLevel = 0, unsigned int arrayElement = 0); 74 75 tcu::ConstPixelBufferAccess readVolume(vk::VkQueue queue, vk::Allocator &allocator, vk::VkImageLayout layout, 76 vk::VkOffset3D offset, int width, int height, int depth, 77 vk::VkImageAspectFlagBits aspect, unsigned int mipLevel = 0, 78 unsigned int arrayElement = 0); 79 80 tcu::ConstPixelBufferAccess readSurfaceLinear(vk::VkOffset3D offset, int width, int height, int depth, 81 vk::VkImageAspectFlagBits aspect, unsigned int mipLevel = 0, 82 unsigned int arrayElement = 0); 83 84 void read(vk::VkQueue queue, vk::Allocator &allocator, vk::VkImageLayout layout, vk::VkOffset3D offset, int width, 85 int height, int depth, unsigned int mipLevel, unsigned int arrayElement, vk::VkImageAspectFlagBits aspect, 86 vk::VkImageType type, void *data); 87 88 void readUsingBuffer(vk::VkQueue queue, vk::Allocator &allocator, vk::VkImageLayout layout, vk::VkOffset3D offset, 89 int width, int height, int depth, unsigned int mipLevel, unsigned int arrayElement, 90 vk::VkImageAspectFlagBits aspect, void *data); 91 92 void readLinear(vk::VkOffset3D offset, int width, int height, int depth, unsigned int mipLevel, 93 unsigned int arrayElement, vk::VkImageAspectFlagBits aspect, void *data); 94 95 void uploadVolume(const tcu::ConstPixelBufferAccess &access, vk::VkQueue queue, vk::Allocator &allocator, 96 vk::VkImageLayout layout, vk::VkOffset3D offset, vk::VkImageAspectFlagBits aspect, 97 unsigned int mipLevel = 0, unsigned int arrayElement = 0); 98 99 void uploadSurface(const tcu::ConstPixelBufferAccess &access, vk::VkQueue queue, vk::Allocator &allocator, 100 vk::VkImageLayout layout, vk::VkOffset3D offset, vk::VkImageAspectFlagBits aspect, 101 unsigned int mipLevel = 0, unsigned int arrayElement = 0); 102 103 void uploadSurface1D(const tcu::ConstPixelBufferAccess &access, vk::VkQueue queue, vk::Allocator &allocator, 104 vk::VkImageLayout layout, vk::VkOffset3D offset, vk::VkImageAspectFlagBits aspect, 105 unsigned int mipLevel = 0, unsigned int arrayElement = 0); 106 107 void uploadSurfaceLinear(const tcu::ConstPixelBufferAccess &access, vk::VkOffset3D offset, int width, int height, 108 int depth, vk::VkImageAspectFlagBits aspect, unsigned int mipLevel = 0, 109 unsigned int arrayElement = 0); 110 111 void upload(vk::VkQueue queue, vk::Allocator &allocator, vk::VkImageLayout layout, vk::VkOffset3D offset, int width, 112 int height, int depth, unsigned int mipLevel, unsigned int arrayElement, 113 vk::VkImageAspectFlagBits aspect, vk::VkImageType type, const void *data); 114 115 void uploadUsingBuffer(vk::VkQueue queue, vk::Allocator &allocator, vk::VkImageLayout layout, vk::VkOffset3D offset, 116 int width, int height, int depth, unsigned int mipLevel, unsigned int arrayElement, 117 vk::VkImageAspectFlagBits aspect, const void *data); 118 119 void uploadLinear(vk::VkOffset3D offset, int width, int height, int depth, unsigned int mipLevel, 120 unsigned int arrayElement, vk::VkImageAspectFlagBits aspect, const void *data); 121 122 de::SharedPtr<Image> copyToLinearImage(vk::VkQueue queue, vk::Allocator &allocator, vk::VkImageLayout layout, 123 vk::VkOffset3D offset, int width, int height, int depth, 124 unsigned int mipLevel, unsigned int arrayElement, 125 vk::VkImageAspectFlagBits aspect, vk::VkImageType type); 126 getFormat(void) const127 const vk::VkFormat &getFormat(void) const 128 { 129 return m_format; 130 } object(void) const131 vk::VkImage object(void) const 132 { 133 return *m_object; 134 } 135 void bindMemory(de::MovePtr<vk::Allocation> allocation); getBoundMemory(void) const136 vk::Allocation getBoundMemory(void) const 137 { 138 return *m_allocation; 139 } 140 141 private: 142 Image(const vk::DeviceInterface &vk, vk::VkDevice device, uint32_t queueFamilyIndex, vk::VkFormat format, 143 const vk::VkExtent3D &extend, uint32_t levelCount, uint32_t layerCount, vk::Move<vk::VkImage> object); 144 145 Image(const Image &other); // Not allowed! 146 Image &operator=(const Image &other); // Not allowed! 147 148 de::MovePtr<vk::Allocation> m_allocation; 149 vk::Unique<vk::VkImage> m_object; 150 151 uint32_t m_queueFamilyIndex; 152 153 vk::VkFormat m_format; 154 vk::VkExtent3D m_extent; 155 uint32_t m_levelCount; 156 uint32_t m_layerCount; 157 158 std::vector<uint8_t> m_pixelAccessData; 159 160 const vk::DeviceInterface &m_vk; 161 vk::VkDevice m_device; 162 }; 163 164 void transition2DImage(const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, 165 vk::VkImageAspectFlags aspectMask, vk::VkImageLayout oldLayout, vk::VkImageLayout newLayout, 166 vk::VkAccessFlags srcAccessMask, vk::VkAccessFlags dstAccessMask, 167 vk::VkPipelineStageFlags srcStageMask, vk::VkPipelineStageFlags dstStageMask, 168 uint32_t numLayers = 1); 169 170 void initialTransitionColor2DImage(const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, 171 vk::VkImageLayout layout, vk::VkAccessFlags dstAccessMask, 172 vk::VkPipelineStageFlags dstStageMask, uint32_t numLayers = 1); 173 174 void initialTransitionDepth2DImage(const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, 175 vk::VkImageLayout layout, vk::VkAccessFlags dstAccessMask, 176 vk::VkPipelineStageFlags dstStageMask); 177 178 void initialTransitionStencil2DImage(const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, vk::VkImage image, 179 vk::VkImageLayout layout, vk::VkAccessFlags dstAccessMask, 180 vk::VkPipelineStageFlags dstStageMask); 181 182 void initialTransitionDepthStencil2DImage(const vk::DeviceInterface &vk, vk::VkCommandBuffer cmdBuffer, 183 vk::VkImage image, vk::VkImageLayout layout, vk::VkAccessFlags dstAccessMask, 184 vk::VkPipelineStageFlags dstStageMask); 185 186 } // namespace Draw 187 } // namespace vkt 188 189 #endif // _VKTDRAWIMAGEOBJECTUTIL_HPP 190