1 #ifndef _VKTIMAGETESTSUTIL_HPP
2 #define _VKTIMAGETESTSUTIL_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
6 *
7 * Copyright (c) 2016 The Khronos Group Inc.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Image Tests Utility Classes
24 *//*--------------------------------------------------------------------*/
25
26 #include "vkDefs.hpp"
27 #include "vkMemUtil.hpp"
28 #include "vkRef.hpp"
29 #include "vkRefUtil.hpp"
30 #include "vkPrograms.hpp"
31 #include "vkTypeUtil.hpp"
32 #include "vkImageUtil.hpp"
33
34 namespace vkt
35 {
36 namespace image
37 {
38
39 enum ImageType
40 {
41 IMAGE_TYPE_1D = 0,
42 IMAGE_TYPE_1D_ARRAY,
43 IMAGE_TYPE_2D,
44 IMAGE_TYPE_2D_ARRAY,
45 IMAGE_TYPE_3D,
46 IMAGE_TYPE_CUBE,
47 IMAGE_TYPE_CUBE_ARRAY,
48 IMAGE_TYPE_BUFFER,
49
50 IMAGE_TYPE_LAST
51 };
52
53 vk::VkImageType mapImageType (const ImageType imageType);
54 vk::VkImageViewType mapImageViewType (const ImageType imageType);
55 std::string getImageTypeName (const ImageType imageType);
56 std::string getShaderImageType (const tcu::TextureFormat& format, const ImageType imageType, const bool multisample = false);
57 std::string getShaderImageFormatQualifier (const tcu::TextureFormat& format);
58
59 class Buffer
60 {
61 public:
62 Buffer (const vk::DeviceInterface& vk,
63 const vk::VkDevice device,
64 vk::Allocator& allocator,
65 const vk::VkBufferCreateInfo& bufferCreateInfo,
66 const vk::MemoryRequirement memoryRequirement);
67
get(void) const68 const vk::VkBuffer& get (void) const { return *m_buffer; }
operator *(void) const69 const vk::VkBuffer& operator* (void) const { return get(); }
getAllocation(void) const70 vk::Allocation& getAllocation (void) const { return *m_allocation; }
71
72 private:
73 de::MovePtr<vk::Allocation> m_allocation;
74 vk::Move<vk::VkBuffer> m_buffer;
75
76 Buffer (const Buffer&); // "deleted"
77 Buffer& operator= (const Buffer&);
78 };
79
80 class Image
81 {
82 public:
83 Image (const vk::DeviceInterface& vk,
84 const vk::VkDevice device,
85 vk::Allocator& allocator,
86 const vk::VkImageCreateInfo& imageCreateInfo,
87 const vk::MemoryRequirement memoryRequirement);
88
get(void) const89 const vk::VkImage& get (void) const { return *m_image; }
operator *(void) const90 const vk::VkImage& operator* (void) const { return get(); }
getAllocation(void) const91 vk::Allocation& getAllocation (void) const { return *m_allocation; }
92
93 private:
94 de::MovePtr<vk::Allocation> m_allocation;
95 vk::Move<vk::VkImage> m_image;
96
97 Image (const Image&); // "deleted"
98 Image& operator= (const Image&);
99 };
100
101 tcu::UVec3 getShaderGridSize (const ImageType imageType, const tcu::UVec3& imageSize); //!< Size used for addresing image in a shader
102 tcu::UVec3 getLayerSize (const ImageType imageType, const tcu::UVec3& imageSize); //!< Size of a single layer
103 deUint32 getNumLayers (const ImageType imageType, const tcu::UVec3& imageSize); //!< Number of array layers (for array and cube types)
104 deUint32 getNumPixels (const ImageType imageType, const tcu::UVec3& imageSize); //!< Number of texels in an image
105 deUint32 getDimensions (const ImageType imageType); //!< Coordinate dimension used for addressing (e.g. 3 (x,y,z) for 2d array)
106 deUint32 getLayerDimensions (const ImageType imageType); //!< Coordinate dimension used for addressing a single layer (e.g. 2 (x,y) for 2d array)
107
108 vk::Move<vk::VkCommandPool> makeCommandPool (const vk::DeviceInterface& vk,
109 const vk::VkDevice device,
110 const deUint32 queueFamilyIndex);
111
112 vk::Move<vk::VkCommandBuffer> makeCommandBuffer (const vk::DeviceInterface& vk,
113 const vk::VkDevice device,
114 const vk::VkCommandPool commandPool);
115
116 vk::Move<vk::VkPipelineLayout> makePipelineLayout (const vk::DeviceInterface& vk,
117 const vk::VkDevice device,
118 const vk::VkDescriptorSetLayout descriptorSetLayout);
119
120 vk::Move<vk::VkPipeline> makeComputePipeline (const vk::DeviceInterface& vk,
121 const vk::VkDevice device,
122 const vk::VkPipelineLayout pipelineLayout,
123 const vk::VkShaderModule shaderModule);
124
125 vk::Move<vk::VkBufferView> makeBufferView (const vk::DeviceInterface& vk,
126 const vk::VkDevice device,
127 const vk::VkBuffer buffer,
128 const vk::VkFormat format,
129 const vk::VkDeviceSize offset,
130 const vk::VkDeviceSize size);
131
132 vk::Move<vk::VkImageView> makeImageView (const vk::DeviceInterface& vk,
133 const vk::VkDevice device,
134 const vk::VkImage image,
135 const vk::VkImageViewType imageViewType,
136 const vk::VkFormat format,
137 const vk::VkImageSubresourceRange subresourceRange);
138
139 vk::Move<vk::VkDescriptorSet> makeDescriptorSet (const vk::DeviceInterface& vk,
140 const vk::VkDevice device,
141 const vk::VkDescriptorPool descriptorPool,
142 const vk::VkDescriptorSetLayout setLayout);
143
144 vk::VkBufferCreateInfo makeBufferCreateInfo (const vk::VkDeviceSize bufferSize,
145 const vk::VkBufferUsageFlags usage);
146
147 vk::VkBufferImageCopy makeBufferImageCopy (const vk::VkExtent3D extent,
148 const deUint32 arraySize);
149
150 vk::VkBufferMemoryBarrier makeBufferMemoryBarrier (const vk::VkAccessFlags srcAccessMask,
151 const vk::VkAccessFlags dstAccessMask,
152 const vk::VkBuffer buffer,
153 const vk::VkDeviceSize offset,
154 const vk::VkDeviceSize bufferSizeBytes);
155
156 vk::VkImageMemoryBarrier makeImageMemoryBarrier (const vk::VkAccessFlags srcAccessMask,
157 const vk::VkAccessFlags dstAccessMask,
158 const vk::VkImageLayout oldLayout,
159 const vk::VkImageLayout newLayout,
160 const vk::VkImage image,
161 const vk::VkImageSubresourceRange subresourceRange);
162
163 void beginCommandBuffer (const vk::DeviceInterface& vk,
164 const vk::VkCommandBuffer cmdBuffer);
165
166 void endCommandBuffer (const vk::DeviceInterface& vk,
167 const vk::VkCommandBuffer cmdBuffer);
168
169 void submitCommandsAndWait (const vk::DeviceInterface& vk,
170 const vk::VkDevice device,
171 const vk::VkQueue queue,
172 const vk::VkCommandBuffer cmdBuffer);
173
getImageSizeBytes(const tcu::IVec3 & imageSize,const vk::VkFormat format)174 inline vk::VkDeviceSize getImageSizeBytes (const tcu::IVec3& imageSize, const vk::VkFormat format)
175 {
176 return tcu::getPixelSize(vk::mapVkFormat(format)) * imageSize.x() * imageSize.y() * imageSize.z();
177 }
178
179 std::string getFormatShortString (const vk::VkFormat format);
180
181 } // image
182 } // vkt
183
184 #endif // _VKTIMAGETESTSUTIL_HPP
185