1 #ifndef _VKTTEXTURETESTUTIL_HPP
2 #define _VKTTEXTURETESTUTIL_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
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
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
15 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 * \brief Texture test utilities.
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 *//*--------------------------------------------------------------------*/
33 #include "tcuDefs.hpp"
34 #include "tcuSurface.hpp"
37 #include "vktTestCase.hpp"
39 #include "gluShaderProgram.hpp"
40 #include "gluTextureTestUtil.hpp"
41 #include "deSharedPtr.hpp"
43 #include "../pipeline/vktPipelineImageUtil.hpp"
61 PROGRAM_2D_FLOAT_BIAS,
64 PROGRAM_2D_SHADOW_BIAS,
71 PROGRAM_1D_FLOAT_BIAS,
74 PROGRAM_1D_SHADOW_BIAS,
81 PROGRAM_CUBE_FLOAT_BIAS,
82 PROGRAM_CUBE_INT_BIAS,
83 PROGRAM_CUBE_UINT_BIAS,
84 PROGRAM_CUBE_SHADOW_BIAS,
86 PROGRAM_1D_ARRAY_FLOAT,
88 PROGRAM_1D_ARRAY_UINT,
89 PROGRAM_1D_ARRAY_SHADOW,
91 PROGRAM_2D_ARRAY_FLOAT,
93 PROGRAM_2D_ARRAY_UINT,
94 PROGRAM_2D_ARRAY_SHADOW,
100 PROGRAM_3D_FLOAT_BIAS,
102 PROGRAM_3D_UINT_BIAS,
104 PROGRAM_CUBE_ARRAY_FLOAT,
105 PROGRAM_CUBE_ARRAY_INT,
106 PROGRAM_CUBE_ARRAY_UINT,
107 PROGRAM_CUBE_ARRAY_SHADOW,
109 PROGRAM_BUFFER_FLOAT,
116 void initializePrograms(vk::SourceCollections& programCollection, glu::Precision texCoordPrecision, const std::vector<Program>& programs);
118 typedef de::SharedPtr<pipeline::TestTexture> TestTextureSp;
119 typedef de::SharedPtr<pipeline::TestTexture2D> TestTexture2DSp;
120 typedef de::SharedPtr<pipeline::TestTextureCube> TestTextureCubeSp;
121 typedef de::SharedPtr<pipeline::TestTexture2DArray> TestTexture2DArraySp;
122 typedef de::SharedPtr<pipeline::TestTexture3D> TestTexture3DSp;
124 class TextureBinding {
137 enum ImageBackingMode
139 IMAGE_BACKING_MODE_REGULAR = 0,
140 IMAGE_BACKING_MODE_SPARSE,
142 IMAGE_BACKING_MODE_LAST
144 TextureBinding (Context& context);
145 TextureBinding (Context& context, const TestTextureSp& textureData, const Type type,
146 const ImageBackingMode backingMode = IMAGE_BACKING_MODE_REGULAR);
147 vk::VkImage getImage (void) { return *m_textureImage; }
148 vk::VkImageView getImageView (void) { return *m_textureImageView; }
149 Type getType (void) { return m_type; }
150 const pipeline::TestTexture& getTestTexture (void) { return *m_textureData; }
151 void updateTextureViewMipLevels (deUint32 baseLevel, deUint32 maxLevel);
154 TextureBinding (const TextureBinding&); // not allowed!
155 TextureBinding& operator= (const TextureBinding&); // not allowed!
157 void updateTextureData (const TestTextureSp& textureData, const Type type);
158 vk::Allocator* createAllocator (void) const;
159 vk::Move<vk::VkDevice> createDevice (void) const;
162 const deUint32 m_queueFamilyIndex;
164 ImageBackingMode m_backingMode;
165 TestTextureSp m_textureData;
166 vk::Move<vk::VkImage> m_textureImage;
167 de::MovePtr<vk::Allocation> m_textureImageMemory;
168 vk::Move<vk::VkImageView> m_textureImageView;
169 vk::Unique<vk::VkDevice> m_device;
170 vk::DeviceDriver m_deviceInterface;
171 const de::UniquePtr<vk::Allocator> m_allocator;
172 std::vector<de::SharedPtr<vk::Allocation> > m_allocations;
175 typedef de::SharedPtr<TextureBinding> TextureBindingSp;
177 class TextureRenderer
180 TextureRenderer (Context& context, vk::VkSampleCountFlagBits sampleCount, deUint32 renderWidth, deUint32 renderHeight);
181 ~TextureRenderer (void);
183 void renderQuad (tcu::Surface& result, int texUnit, const float* texCoord, glu::TextureTestUtil::TextureType texType);
184 void renderQuad (tcu::Surface& result, int texUnit, const float* texCoord, const glu::TextureTestUtil::ReferenceParams& params);
185 void renderQuad (tcu::Surface& result,
186 const float* positions,
188 const float* texCoord,
189 const glu::TextureTestUtil::ReferenceParams& params,
190 const float maxAnisotropy);
192 void clearImage (vk::VkImage image);
193 void add2DTexture (const TestTexture2DSp& texture,
194 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
195 const pipeline::TestTexture2D& get2DTexture (int textureIndex) const;
197 void addCubeTexture (const TestTextureCubeSp& texture,
198 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
199 const pipeline::TestTextureCube& getCubeTexture (int textureIndex) const;
201 void add2DArrayTexture (const TestTexture2DArraySp& texture,
202 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
203 const pipeline::TestTexture2DArray& get2DArrayTexture (int textureIndex) const;
205 void add3DTexture (const TestTexture3DSp& texture,
206 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
207 const pipeline::TestTexture3D& get3DTexture (int textureIndex) const;
209 void setViewport (float viewportX, float viewportY, float viewportW, float viewportH);
211 TextureBinding* getTextureBinding (int textureIndex) const;
213 deUint32 getRenderWidth (void) const;
214 deUint32 getRenderHeight (void) const;
217 TextureRenderer (const TextureRenderer& other);
218 TextureRenderer& operator= (const TextureRenderer& other);
223 const deUint32 m_renderWidth;
224 const deUint32 m_renderHeight;
225 const vk::VkSampleCountFlagBits m_sampleCount;
226 const deBool m_multisampling;
228 const vk::VkFormat m_imageFormat;
229 const tcu::TextureFormat m_textureFormat;
231 vk::Move<vk::VkImage> m_image;
232 de::MovePtr<vk::Allocation> m_imageMemory;
233 vk::Move<vk::VkImageView> m_imageView;
235 vk::Move<vk::VkImage> m_resolvedImage;
236 de::MovePtr<vk::Allocation> m_resolvedImageMemory;
237 vk::Move<vk::VkImageView> m_resolvedImageView;
239 vk::Move<vk::VkCommandPool> m_commandPool;
240 vk::Move<vk::VkRenderPass> m_renderPass;
241 vk::Move<vk::VkFramebuffer> m_frameBuffer;
243 vk::Move<vk::VkDescriptorPool> m_descriptorPool;
245 vk::Move<vk::VkBuffer> m_uniformBuffer;
246 de::MovePtr<vk::Allocation> m_uniformBufferMemory;
247 const vk::VkDeviceSize m_uniformBufferSize;
249 vk::Move<vk::VkBuffer> m_vertexIndexBuffer;
250 de::MovePtr<vk::Allocation> m_vertexIndexBufferMemory;
251 static const vk::VkDeviceSize s_vertexIndexBufferSize;
252 static const deUint16 s_vertexIndices[6];
254 vk::Move<vk::VkFence> m_fence;
256 vk::Move<vk::VkBuffer> m_resultBuffer;
257 de::MovePtr<vk::Allocation> m_resultBufferMemory;
258 const vk::VkDeviceSize m_resultBufferSize;
260 std::vector<TextureBindingSp> m_textureBindings;
262 float m_viewportOffsetX;
263 float m_viewportOffsetY;
264 float m_viewportWidth;
265 float m_viewportHeight;
268 vk::Move<vk::VkDescriptorSet> makeDescriptorSet (const vk::VkDescriptorPool descriptorPool, const vk::VkDescriptorSetLayout setLayout) const;
269 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;
273 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::WrapMode wrapV, tcu::Sampler::WrapMode wrapW, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode);
274 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::WrapMode wrapV, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode);
275 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode);
277 TestTexture2DSp loadTexture2D (const tcu::Archive& archive, const std::vector<std::string>& filenames);
278 TestTextureCubeSp loadTextureCube (const tcu::Archive& archive, const std::vector<std::string>& filenames);
280 template <typename INSTANCE_TYPE>
281 class TextureTestCase : public TestCase
284 TextureTestCase (tcu::TestContext& context, const std::string& name, const std::string& description, const typename INSTANCE_TYPE::ParameterType& testParameters)
285 : TestCase (context, name, description)
286 , m_testsParameters (testParameters)
289 virtual TestInstance* createInstance (Context& context) const
291 return new INSTANCE_TYPE(context, m_testsParameters);
294 virtual void initPrograms (vk::SourceCollections& programCollection) const
296 initializePrograms(programCollection, m_testsParameters.texCoordPrecision, m_testsParameters.programs);
300 const typename INSTANCE_TYPE::ParameterType m_testsParameters;
303 struct TextureCommonTestCaseParameters
305 TextureCommonTestCaseParameters (void);
307 vk::VkSampleCountFlagBits sampleCount;
308 glu::Precision texCoordPrecision;
310 tcu::Sampler::FilterMode minFilter;
311 tcu::Sampler::FilterMode magFilter;
312 tcu::Sampler::WrapMode wrapS;
313 tcu::Sampler::WrapMode wrapT;
317 std::vector<util::Program> programs;
320 struct Texture2DTestCaseParameters : public TextureCommonTestCaseParameters
322 Texture2DTestCaseParameters (void);
327 struct TextureCubeTestCaseParameters : public TextureCommonTestCaseParameters
329 TextureCubeTestCaseParameters (void);
333 struct Texture2DArrayTestCaseParameters : public Texture2DTestCaseParameters
335 Texture2DArrayTestCaseParameters(void);
339 struct Texture3DTestCaseParameters : public Texture2DTestCaseParameters
341 Texture3DTestCaseParameters (void);
342 tcu::Sampler::WrapMode wrapR;
350 #endif // _VKTTEXTURETESTUTIL_HPP