1 #ifndef _VKTTEXTURETESTUTIL_HPP 2 #define _VKTTEXTURETESTUTIL_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2016 The Khronos Group Inc. 8 * Copyright (c) 2016 Samsung Electronics Co., Ltd. 9 * Copyright (c) 2014 The Android Open Source Project 10 * 11 * Licensed under the Apache License, Version 2.0 (the "License"); 12 * you may not use this file except in compliance with the License. 13 * You may obtain a copy of the License at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, software 18 * distributed under the License is distributed on an "AS IS" BASIS, 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 * See the License for the specific language governing permissions and 21 * limitations under the License. 22 * 23 *//*! 24 * \file 25 * \brief Texture test utilities. 26 * 27 * About coordinates: 28 * + Quads consist of 2 triangles, rendered using explicit indices. 29 * + All TextureTestUtil functions and classes expect texture coordinates 30 * for quads to be specified in order (-1, -1), (-1, 1), (1, -1), (1, 1). 31 *//*--------------------------------------------------------------------*/ 32 33 #include "tcuDefs.hpp" 34 #include "tcuSurface.hpp" 35 36 #include "vkDefs.hpp" 37 #include "vkTypeUtil.hpp" 38 #include "vktTestCase.hpp" 39 40 #include "gluShaderProgram.hpp" 41 #include "gluTextureTestUtil.hpp" 42 #include "deSharedPtr.hpp" 43 44 #include "../pipeline/vktPipelineImageUtil.hpp" 45 46 namespace vkt 47 { 48 49 namespace texture 50 { 51 52 namespace util 53 { 54 55 enum Program 56 { 57 PROGRAM_2D_FLOAT = 0, 58 PROGRAM_2D_INT, 59 PROGRAM_2D_UINT, 60 PROGRAM_2D_SHADOW, 61 62 PROGRAM_2D_FLOAT_BIAS, 63 PROGRAM_2D_INT_BIAS, 64 PROGRAM_2D_UINT_BIAS, 65 PROGRAM_2D_SHADOW_BIAS, 66 67 PROGRAM_1D_FLOAT, 68 PROGRAM_1D_INT, 69 PROGRAM_1D_UINT, 70 PROGRAM_1D_SHADOW, 71 72 PROGRAM_1D_FLOAT_BIAS, 73 PROGRAM_1D_INT_BIAS, 74 PROGRAM_1D_UINT_BIAS, 75 PROGRAM_1D_SHADOW_BIAS, 76 77 PROGRAM_CUBE_FLOAT, 78 PROGRAM_CUBE_INT, 79 PROGRAM_CUBE_UINT, 80 PROGRAM_CUBE_SHADOW, 81 82 PROGRAM_CUBE_FLOAT_BIAS, 83 PROGRAM_CUBE_INT_BIAS, 84 PROGRAM_CUBE_UINT_BIAS, 85 PROGRAM_CUBE_SHADOW_BIAS, 86 87 PROGRAM_1D_ARRAY_FLOAT, 88 PROGRAM_1D_ARRAY_INT, 89 PROGRAM_1D_ARRAY_UINT, 90 PROGRAM_1D_ARRAY_SHADOW, 91 92 PROGRAM_2D_ARRAY_FLOAT, 93 PROGRAM_2D_ARRAY_INT, 94 PROGRAM_2D_ARRAY_UINT, 95 PROGRAM_2D_ARRAY_SHADOW, 96 97 PROGRAM_3D_FLOAT, 98 PROGRAM_3D_INT, 99 PROGRAM_3D_UINT, 100 101 PROGRAM_3D_FLOAT_BIAS, 102 PROGRAM_3D_INT_BIAS, 103 PROGRAM_3D_UINT_BIAS, 104 105 PROGRAM_CUBE_ARRAY_FLOAT, 106 PROGRAM_CUBE_ARRAY_INT, 107 PROGRAM_CUBE_ARRAY_UINT, 108 PROGRAM_CUBE_ARRAY_SHADOW, 109 110 PROGRAM_BUFFER_FLOAT, 111 PROGRAM_BUFFER_INT, 112 PROGRAM_BUFFER_UINT, 113 114 PROGRAM_LAST 115 }; 116 117 void initializePrograms(vk::SourceCollections& programCollection, glu::Precision texCoordPrecision, const std::vector<Program>& programs); 118 119 typedef de::SharedPtr<pipeline::TestTexture> TestTextureSp; 120 typedef de::SharedPtr<pipeline::TestTexture2D> TestTexture2DSp; 121 typedef de::SharedPtr<pipeline::TestTextureCube> TestTextureCubeSp; 122 typedef de::SharedPtr<pipeline::TestTexture2DArray> TestTexture2DArraySp; 123 typedef de::SharedPtr<pipeline::TestTexture3D> TestTexture3DSp; 124 125 class TextureBinding { 126 public: 127 enum Type 128 { 129 TYPE_NONE = 0, 130 TYPE_2D, 131 TYPE_CUBE_MAP, 132 TYPE_2D_ARRAY, 133 TYPE_3D, 134 135 TYPE_LAST 136 }; 137 138 enum ImageBackingMode 139 { 140 IMAGE_BACKING_MODE_REGULAR = 0, 141 IMAGE_BACKING_MODE_SPARSE, 142 143 IMAGE_BACKING_MODE_LAST 144 }; 145 TextureBinding (Context& context); 146 TextureBinding (Context& context, const TestTextureSp& textureData, const Type type, 147 const ImageBackingMode backingMode = IMAGE_BACKING_MODE_REGULAR, 148 const vk::VkComponentMapping componentMapping = vk::makeComponentMappingRGBA()); getImage(void)149 vk::VkImage getImage (void) { return *m_textureImage; } getImageView(void)150 vk::VkImageView getImageView (void) { return *m_textureImageView; } getType(void)151 Type getType (void) { return m_type; } getTestTexture(void)152 const pipeline::TestTexture& getTestTexture (void) { return *m_textureData; } 153 void updateTextureViewMipLevels (deUint32 baseLevel, deUint32 maxLevel); 154 155 private: 156 TextureBinding (const TextureBinding&); // not allowed! 157 TextureBinding& operator= (const TextureBinding&); // not allowed! 158 159 void updateTextureData (const TestTextureSp& textureData, const Type type); 160 161 Context& m_context; 162 Type m_type; 163 ImageBackingMode m_backingMode; 164 TestTextureSp m_textureData; 165 vk::Move<vk::VkImage> m_textureImage; 166 de::MovePtr<vk::Allocation> m_textureImageMemory; 167 vk::Move<vk::VkImageView> m_textureImageView; 168 std::vector<de::SharedPtr<vk::Allocation> > m_allocations; 169 vk::VkComponentMapping m_componentMapping; 170 }; 171 172 typedef de::SharedPtr<TextureBinding> TextureBindingSp; 173 174 class TextureRenderer 175 { 176 public: 177 TextureRenderer (Context& context, vk::VkSampleCountFlagBits sampleCount, deUint32 renderWidth, deUint32 renderHeight, vk::VkComponentMapping componentMapping = vk::makeComponentMappingRGBA()); 178 ~TextureRenderer (void); 179 180 void renderQuad (tcu::Surface& result, int texUnit, const float* texCoord, glu::TextureTestUtil::TextureType texType); 181 void renderQuad (tcu::Surface& result, int texUnit, const float* texCoord, const glu::TextureTestUtil::ReferenceParams& params); 182 void renderQuad (tcu::Surface& result, 183 const float* positions, 184 const int texUnit, 185 const float* texCoord, 186 const glu::TextureTestUtil::ReferenceParams& params, 187 const float maxAnisotropy); 188 189 void clearImage (vk::VkImage image); 190 void add2DTexture (const TestTexture2DSp& texture, 191 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR); 192 const pipeline::TestTexture2D& get2DTexture (int textureIndex) const; 193 194 void addCubeTexture (const TestTextureCubeSp& texture, 195 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR); 196 const pipeline::TestTextureCube& getCubeTexture (int textureIndex) const; 197 198 void add2DArrayTexture (const TestTexture2DArraySp& texture, 199 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR); 200 const pipeline::TestTexture2DArray& get2DArrayTexture (int textureIndex) const; 201 202 void add3DTexture (const TestTexture3DSp& texture, 203 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR); 204 const pipeline::TestTexture3D& get3DTexture (int textureIndex) const; 205 206 void setViewport (float viewportX, float viewportY, float viewportW, float viewportH); 207 208 TextureBinding* getTextureBinding (int textureIndex) const; 209 210 deUint32 getRenderWidth (void) const; 211 deUint32 getRenderHeight (void) const; 212 213 protected: 214 TextureRenderer (const TextureRenderer& other); 215 TextureRenderer& operator= (const TextureRenderer& other); 216 217 Context& m_context; 218 tcu::TestLog& m_log; 219 220 const deUint32 m_renderWidth; 221 const deUint32 m_renderHeight; 222 const vk::VkSampleCountFlagBits m_sampleCount; 223 const deBool m_multisampling; 224 225 const vk::VkFormat m_imageFormat; 226 const tcu::TextureFormat m_textureFormat; 227 228 vk::Move<vk::VkImage> m_image; 229 de::MovePtr<vk::Allocation> m_imageMemory; 230 vk::Move<vk::VkImageView> m_imageView; 231 232 vk::Move<vk::VkImage> m_resolvedImage; 233 de::MovePtr<vk::Allocation> m_resolvedImageMemory; 234 vk::Move<vk::VkImageView> m_resolvedImageView; 235 236 vk::Move<vk::VkCommandPool> m_commandPool; 237 vk::Move<vk::VkRenderPass> m_renderPass; 238 vk::Move<vk::VkFramebuffer> m_frameBuffer; 239 240 vk::Move<vk::VkDescriptorPool> m_descriptorPool; 241 242 vk::Move<vk::VkBuffer> m_uniformBuffer; 243 de::MovePtr<vk::Allocation> m_uniformBufferMemory; 244 const vk::VkDeviceSize m_uniformBufferSize; 245 246 vk::Move<vk::VkBuffer> m_vertexIndexBuffer; 247 de::MovePtr<vk::Allocation> m_vertexIndexBufferMemory; 248 static const vk::VkDeviceSize s_vertexIndexBufferSize; 249 static const deUint16 s_vertexIndices[6]; 250 251 vk::Move<vk::VkBuffer> m_resultBuffer; 252 de::MovePtr<vk::Allocation> m_resultBufferMemory; 253 const vk::VkDeviceSize m_resultBufferSize; 254 255 std::vector<TextureBindingSp> m_textureBindings; 256 257 float m_viewportOffsetX; 258 float m_viewportOffsetY; 259 float m_viewportWidth; 260 float m_viewportHeight; 261 262 vk::VkComponentMapping m_componentMapping; 263 264 private: 265 vk::Move<vk::VkDescriptorSet> makeDescriptorSet (const vk::VkDescriptorPool descriptorPool, const vk::VkDescriptorSetLayout setLayout) const; 266 void addImageTransitionBarrier (vk::VkCommandBuffer commandBuffer, vk::VkImage image, vk::VkPipelineStageFlags srcStageMask, vk::VkPipelineStageFlags dstStageMask, vk::VkAccessFlags srcAccessMask, vk::VkAccessFlags dstAccessMask, vk::VkImageLayout oldLayout, vk::VkImageLayout newLayout) const; 267 268 }; 269 270 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::WrapMode wrapV, tcu::Sampler::WrapMode wrapW, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode, bool normalizedCoords = true); 271 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::WrapMode wrapV, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode, bool normalizedCoords = true); 272 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode, bool normalizedCoords = true); 273 274 TestTexture2DSp loadTexture2D (const tcu::Archive& archive, const std::vector<std::string>& filenames); 275 TestTextureCubeSp loadTextureCube (const tcu::Archive& archive, const std::vector<std::string>& filenames); 276 277 template <typename INSTANCE_TYPE> 278 class TextureTestCase : public TestCase 279 { 280 public: TextureTestCase(tcu::TestContext & context,const std::string & name,const std::string & description,const typename INSTANCE_TYPE::ParameterType & testParameters)281 TextureTestCase (tcu::TestContext& context, const std::string& name, const std::string& description, const typename INSTANCE_TYPE::ParameterType& testParameters) 282 : TestCase (context, name, description) 283 , m_testsParameters (testParameters) 284 {} 285 createInstance(Context & context) const286 virtual TestInstance* createInstance (Context& context) const 287 { 288 return new INSTANCE_TYPE(context, m_testsParameters); 289 } 290 initPrograms(vk::SourceCollections & programCollection) const291 virtual void initPrograms (vk::SourceCollections& programCollection) const 292 { 293 initializePrograms(programCollection, m_testsParameters.texCoordPrecision, m_testsParameters.programs); 294 } 295 296 protected: 297 const typename INSTANCE_TYPE::ParameterType m_testsParameters; 298 }; 299 300 struct TextureCommonTestCaseParameters 301 { 302 TextureCommonTestCaseParameters (void); 303 304 vk::VkSampleCountFlagBits sampleCount; 305 glu::Precision texCoordPrecision; 306 307 tcu::Sampler::FilterMode minFilter; 308 tcu::Sampler::FilterMode magFilter; 309 tcu::Sampler::WrapMode wrapS; 310 tcu::Sampler::WrapMode wrapT; 311 312 vk::VkFormat format; 313 314 std::vector<util::Program> programs; 315 316 deBool unnormal; 317 }; 318 319 struct Texture2DTestCaseParameters : public TextureCommonTestCaseParameters 320 { 321 Texture2DTestCaseParameters (void); 322 int width; 323 int height; 324 bool mipmaps; 325 }; 326 327 struct TextureCubeTestCaseParameters : public TextureCommonTestCaseParameters 328 { 329 TextureCubeTestCaseParameters (void); 330 int size; 331 }; 332 333 struct Texture2DArrayTestCaseParameters : public Texture2DTestCaseParameters 334 { 335 Texture2DArrayTestCaseParameters(void); 336 int numLayers; 337 }; 338 339 struct Texture3DTestCaseParameters : public Texture2DTestCaseParameters 340 { 341 Texture3DTestCaseParameters (void); 342 tcu::Sampler::WrapMode wrapR; 343 int depth; 344 }; 345 346 } // util 347 } // texture 348 } // vkt 349 350 #endif // _VKTTEXTURETESTUTIL_HPP 351