Improvements to sample verification code
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / texture_filtering / vktSampleVerifier.hpp
1 #ifndef _VKTSAMPLEVERIFIER_HPP
2 #define _VKTSAMPLEVERIFIER_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2016 Google 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 GPU image sample verification
24  *//*--------------------------------------------------------------------*/
25
26 #include "vkDefs.hpp"
27
28 #include "deUniquePtr.hpp"
29
30 #include "tcuFloatFormat.hpp"
31 #include "tcuTexture.hpp"
32 #include "tcuVector.hpp"
33
34 #include <iostream>
35 #include <string>
36 #include <vector>
37
38 namespace vkt
39 {
40 namespace texture_filtering
41 {
42
43 struct SampleArguments
44 {
45         tcu::Vec4       coord;
46         tcu::Vec4       dPdx;
47         tcu::Vec4       dPdy;
48         float           layer;
49         float           lod;
50         float           lodBias;
51         float           dRef;
52 };
53
54 enum LookupLodMode
55 {
56         LOOKUP_LOD_MODE_DERIVATIVES = 0,
57         LOOKUP_LOD_MODE_LOD,
58
59         LOOKUP_LOD_MODE_LAST
60 };
61
62 struct SampleLookupSettings
63 {
64         LookupLodMode   lookupLodMode;
65         bool                    hasLodBias;
66         bool                    isProjective;
67 };
68
69 enum WrappingMode
70 {
71         WRAPPING_MODE_REPEAT = 0,
72         WRAPPING_MODE_MIRRORED_REPEAT,
73         WRAPPING_MODE_CLAMP_TO_EDGE,
74         WRAPPING_MODE_CLAMP_TO_BORDER,
75         WRAPPING_MODE_MIRROR_CLAMP_TO_EDGE,
76
77         WRAPPING_MODE_LAST
78 };
79
80 struct SamplerParameters
81 {
82         vk::VkFilter                            magFilter;
83         vk::VkFilter                            minFilter;
84         vk::VkSamplerMipmapMode         mipmapFilter;
85
86         vk::VkSamplerAddressMode        wrappingModeU;
87         vk::VkSamplerAddressMode        wrappingModeV;
88         vk::VkSamplerAddressMode        wrappingModeW;
89
90         vk::VkBorderColor                       borderColor;
91
92         float                                           lodBias;
93         float                                           minLod;
94         float                                           maxLod;
95
96         bool                                            isUnnormalized;
97         bool                                            isCompare;
98 };
99
100 enum ImgDim
101 {
102         IMG_DIM_INVALID = 0,
103         IMG_DIM_1D,
104         IMG_DIM_2D,
105         IMG_DIM_3D,
106         IMG_DIM_CUBE,
107
108         IMG_DIM_LAST
109 };
110
111 struct ImageViewParameters
112 {
113         ImgDim                  dim;
114         vk::VkFormat    format;
115         tcu::IVec3              size;
116         int                             levels;
117
118         bool                    isArrayed;
119         int                             arrayLayers;
120 };
121
122 class SampleVerifier
123 {
124 public:
125         SampleVerifier                                          (const ImageViewParameters&                                                     imParams,
126                                                                                  const SamplerParameters&                                                       samplerParams,
127                                                                                  const SampleLookupSettings&                                            sampleLookupSettings,
128                                                                                  int                                                                                            coordBits,
129                                                                                  int                                                                                            mipmapBits,
130                                                                                  const std::vector<tcu::ConstPixelBufferAccess>&        pba);
131
132         bool verifySample                                       (const SampleArguments&                                                         args,
133                                                                                  const tcu::Vec4&                                                                       result) const;
134
135         bool verifySampleReport                         (const SampleArguments&                                                         args,
136                                                                                  const tcu::Vec4&                                                                       result,
137                                                                                  std::string&                                                                           report) const;
138
139 private:
140
141         bool verifySampleFiltered                       (const tcu::Vec4&                                                                       result,
142                                                                                  const tcu::IVec3&                                                                  baseTexelHi,
143                                                                                  const tcu::IVec3&                                                                  baseTexelLo,
144                                                                                  const tcu::IVec3&                                                                  texelGridOffsetHi,
145                                                                                  const tcu::IVec3&                                                                  texelGridOffsetLo,
146                                                                                  int                                                                                            layer,
147                                                                                  int                                                                                            levelHi,
148                                                                                  const tcu::Vec2&                                                                       lodFracBounds,
149                                                                                  vk::VkFilter                                                                           filter,
150                                                                                  vk::VkSamplerMipmapMode                                                        mipmapFilter,
151                                                                                  std::ostream&                                                                          report) const;
152
153         bool verifySampleTexelGridCoords        (const SampleArguments&                                                         args,
154                                                                                  const tcu::Vec4&                                                                       result,
155                                                                                  const tcu::IVec3&                                                                      gridCoordHi,
156                                                                                  const tcu::IVec3&                                                                      gridCoordLo,
157                                                                                  const tcu::Vec2&                                                                       lodBounds,
158                                                                                  int                                                                                            level,
159                                                                                  vk::VkSamplerMipmapMode                                                        mipmapFilter,
160                                                                                  std::ostream&                                                                          report) const;
161
162         bool verifySampleMipmapLevel            (const SampleArguments&                                                         args,
163                                                                                  const tcu::Vec4&                                                                       result,
164                                                                                  const tcu::Vec4&                                                                       coord,
165                                                                                  const tcu::Vec2&                                                                       lodFracBounds,
166                                                                                  int                                                                                            level,
167                                                                                  std::ostream&                                                                          report) const;
168
169         bool verifySampleCubemapFace            (const SampleArguments&                                                         args,
170                                                                                  const tcu::Vec4&                                                                       result,
171                                                                                  const tcu::Vec4&                                                                       coord,
172                                                                                  const tcu::Vec4&                                                                       dPdx,
173                                                                                  const tcu::Vec4&                                                                       dPdy,
174                                                                                  int                                                                                            face,
175                                                                                  std::ostream&                                                                          report) const;
176
177         bool verifySampleImpl                           (const SampleArguments&                                                         args,
178                                                                                  const tcu::Vec4&                                                                       result,
179                                                                                  std::ostream&                                                                          report) const;
180
181         bool coordOutOfRange                            (const tcu::IVec3&                                                                      coord,
182                                                                                  int                                                                                            compNdx,
183                                                                                  int                                                                                            level) const;
184
185         void fetchTexel                                         (const tcu::IVec3&                                                                      coordIn,
186                                                                                  int                                                                                            layer,
187                                                                                  int                                                                                            level,
188                                                                                  vk::VkFilter                                                                           filter,
189                                                                                  tcu::Vec4&                                                                             resultMin,
190                                                                                  tcu::Vec4&                                                                             resultMax) const;
191
192         void fetchTexelWrapped                          (const tcu::IVec3&                                                                      coord,
193                                                                                  int                                                                                            layer,
194                                                                                  int                                                                                            level,
195                                                                                  tcu::Vec4&                                                                                     resultMin,
196                                                                                  tcu::Vec4&                                                                             resultMax) const;
197
198     void getFilteredSample1D                    (const tcu::IVec3&                                                                      texelBase,
199                                                                                  float                                                                                          weight,
200                                                                                  int                                                                                            layer,
201                                                                                  int                                                                                            level,
202                                                                                  tcu::Vec4&                                                                             resultMin,
203                                                                                  tcu::Vec4&                                                                             resultMax) const;
204
205         void getFilteredSample2D                        (const tcu::IVec3&                                                                      texelBase,
206                                                                                  const tcu::Vec2&                                                                       weights,
207                                                                                  int                                                                                            layer,
208                                                                                  int                                                                                            level,
209                                                                                  tcu::Vec4&                                                                             resultMin,
210                                                                                  tcu::Vec4&                                                                             resultMax) const;
211
212         void getFilteredSample3D                        (const tcu::IVec3&                                                                      texelBase,
213                                                                                  const tcu::Vec3&                                                                       weights,
214                                                                                  int                                                                                            layer,
215                                                                                  int                                                                                            level,
216                                                                                  tcu::Vec4&                                                                             resultMin,
217                                                                                  tcu::Vec4&                                                                             resultMax) const;
218
219         void getFilteredSample                          (const tcu::IVec3&                                                                      texelBase,
220                                                                                  const tcu::Vec3&                                                                       weights,
221                                                                                  int                                                                                            layer,
222                                                                                  int                                                                                            level,
223                                                                                  tcu::Vec4&                                                                             resultMin,
224                                                                                  tcu::Vec4&                                                                             resultMax) const;
225
226         void getMipmapStepBounds                        (const tcu::Vec2&                                                                       lodFracBounds,
227                                                                                  deInt32&                                                                                       stepMin,
228                                                                                  deInt32&                                                                                       stepMax) const;
229
230         const tcu::FloatFormat                                                  m_internalFormat;
231
232         const ImageViewParameters&                                              m_imParams;
233         const SamplerParameters&                                                m_samplerParams;
234         const SampleLookupSettings&                                             m_sampleLookupSettings;
235
236     const int                                                                           m_coordBits;
237         const int                                                                               m_mipmapBits;
238
239         const int                                                                               m_unnormalizedDim;
240
241         const std::vector<tcu::ConstPixelBufferAccess>& m_pba;
242 };
243
244 } // texture_filtering
245 } // vkt
246
247 #endif // _VKTSAMPLEVERIFIER_HPP