Improvements to sample verification code
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / texture_filtering / vktSampleVerifierUtil.hpp
1 #ifndef _VKTSAMPLEVERIFIERUTIL_HPP
2 #define _VKTSAMPLEVERIFIERUTIL_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 "vktSampleVerifier.hpp"
27
28 #include "deMath.h"
29 #include "tcuFloatFormat.hpp"
30 #include "tcuTexture.hpp"
31 #include "vkDefs.hpp"
32
33 namespace vkt
34 {
35 namespace texture_filtering
36 {
37 namespace util
38 {
39
40 float           addUlp                                          (float                                                  num,
41                                                                                  deInt32                                                ulp);
42
43 deInt32         mod                                                     (const deInt32                                  a,
44                                                                                  const deInt32                                  n);
45 deInt32     mirror                                              (const deInt32                                  n);
46
47 tcu::Vec2       calcLodBounds                           (const tcu::Vec3&                               dPdx,
48                                                                                  const tcu::Vec3&                               dPdy,
49                                                                                  const tcu::IVec3                               size,
50                                                                                  const float                                    lodBias,
51                                                                                  const float                                    lodMin,
52                                                                                  const float                                    lodMax);
53 tcu::UVec2      calcLevelBounds                         (const tcu::Vec2&                               lodBounds,
54                                                                                  const int                                              levelCount,
55                                                                                  vk::VkSamplerMipmapMode                mipmapFilter);
56 tcu::Vec2       calcLevelLodBounds                      (const tcu::Vec2&                               lodBounds,
57                                                                                  int                                                    level);
58
59 void            wrapTexelGridCoordLinear        (tcu::IVec3&                                    baseTexel,
60                                                                                  tcu::IVec3&                                    texelGridOffset,
61                                                                                  const int                                              coordBits,
62                                                                                  const ImgDim                                   dim);
63 void            calcTexelBaseOffset                     (const tcu::IVec3&                              gridCoord,
64                                                                                  const int                                              coordBits,
65                                                                                  tcu::IVec3&                                    baseTexel,
66                                                                                  tcu::IVec3&                                    texelGridOffset);
67 void            calcTexelGridCoordRange         (const tcu::Vec3&                               unnormalizedCoordMin,
68                                                                                  const tcu::Vec3&                               unnormalizedCoordMax,
69                                                                                  const int                                              coordBits,
70                                                                                  tcu::IVec3&                                    gridCoordMin,
71                                                                                  tcu::IVec3&                                    gridCoordMax);
72 void            calcUnnormalizedCoordRange      (const tcu::Vec4&                               coord,
73                                                                                  const tcu::IVec3&                              levelSize,
74                                                                                  const tcu::FloatFormat&                internalFormat,
75                                                                                  tcu::Vec3&                                             unnormalizedCoordMin,
76                                                                                  tcu::Vec3&                                             unnormalizedCoordMax);
77 void            calcCubemapFaceCoords           (const tcu::Vec3&                               r,
78                                                                                  const tcu::Vec3&                               drdx,
79                                                                                  const tcu::Vec3&                               drdy,
80                                                                                  const int                                              faceNdx,
81                                                                                  tcu::Vec2&                                             coordFace,
82                                                                                  tcu::Vec2&                                             dPdxFace,
83                                                                                  tcu::Vec2&                                             dPdyFace);
84 int             calcCandidateCubemapFaces       (const tcu::Vec3&                               r);
85 deInt32         wrapTexelCoord                          (const deInt32                                  coord,
86                                                                                  const int                                              size,
87                                                                                  const vk::VkSamplerAddressMode wrap);
88 void            wrapCubemapEdge                         (const tcu::IVec2&                              coord,
89                                                                                  const tcu::IVec2&                              size,
90                                                                                  const int                                              faceNdx,
91                                                                                  tcu::IVec2&                                    newCoord,
92                                                                                  int&                                                   newFaceNdx);
93 void            wrapCubemapCorner                       (const tcu::IVec2&                              coord,
94                                                                                  const tcu::IVec2&                              size,
95                                                                                  const int                                              faceNdx,
96                                                                                  int&                                                   adjacentFace1,
97                                                                                  int&                                                   adjacentFace2,
98                                                                                  tcu::IVec2&                                    cornerCoord0,
99                                                                                  tcu::IVec2&                                    cornerCoord1,
100                                                                                  tcu::IVec2&                                    cornerCoord2);
101
102 void            convertFormat                           (const void*                                    pixelPtr,
103                                                                                  tcu::TextureFormat                             texFormat,
104                                                                                  tcu::FloatFormat                               internalFormat,
105                                                                                  tcu::Vec4&                                             resultMin,
106                                                                                  tcu::Vec4&                                             resultMax);
107
108 template <int Size>
109 bool isEqualRelEpsilon (const tcu::Vector<float, Size>& a, const tcu::Vector<float, Size>& b, const float epsilon)
110 {
111         for (int compNdx = 0; compNdx < Size; ++compNdx)
112         {
113                 if (!isEqualRelEpsilon(a[compNdx], b[compNdx], epsilon))
114                 {
115                         return false;
116                 }
117         }
118
119         return true;
120 }
121
122 template <int Size>
123 bool isInRange (const tcu::Vector<float, Size>& v, const tcu::Vector<float, Size>& min, const tcu::Vector<float, Size>& max)
124 {
125         for (int compNdx = 0; compNdx < Size; ++compNdx)
126         {
127                 if (v[compNdx] < min[compNdx] || v[compNdx] > max[compNdx])
128                 {
129                         return false;
130                 }
131         }
132
133         return true;
134 }
135
136 template <int Size>
137 tcu::Vector<float, Size> floor (const tcu::Vector<float, Size>& v)
138 {
139         tcu::Vector<float, Size> result;
140
141         for (int compNdx = 0; compNdx < Size; ++compNdx)
142         {
143                 result[compNdx] = (float)deFloor(v[compNdx]);
144         }
145
146         return result;
147 }
148
149 template <int Size>
150 tcu::Vector<float, Size> ceil (const tcu::Vector<float, Size>& v)
151 {
152         tcu::Vector<float, Size> result;
153
154         for (int compNdx = 0; compNdx < Size; ++compNdx)
155         {
156                 result[compNdx] = (float)deCeil(v[compNdx]);
157         }
158
159         return result;
160 }
161
162 template <int Size>
163 tcu::Vector<float, Size> abs (const tcu::Vector<float, Size>& v)
164 {
165         tcu::Vector<float, Size> result;
166
167         for (int compNdx = 0; compNdx < Size; ++compNdx)
168         {
169                 result[compNdx] = de::abs(v[compNdx]);
170         }
171
172         return result;
173 }
174
175 } // util
176 } // texture_filtering
177 } // vkt
178
179 #endif // _VKTSAMPLEVERIFIERUTIL_HPP