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