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
36 {
37 namespace util
38 {
39
40 float addUlp(float num, int32_t ulp);
41
42 int32_t mod(const int32_t a, const int32_t n);
43 int32_t mirror(const int32_t n);
44
45 tcu::Vec2 calcLodBounds(const tcu::Vec3 &dPdx, const tcu::Vec3 &dPdy, const tcu::IVec3 size, const float lodBias,
46 const float lodMin, const float lodMax);
47 tcu::UVec2 calcLevelBounds(const tcu::Vec2 &lodBounds, const int levelCount, vk::VkSamplerMipmapMode mipmapFilter);
48 tcu::Vec2 calcLevelLodBounds(const tcu::Vec2 &lodBounds, int level);
49
50 void wrapTexelGridCoordLinear(tcu::IVec3 &baseTexel, tcu::IVec3 &texelGridOffset, const int coordBits,
51 const ImgDim dim);
52 void calcTexelBaseOffset(const tcu::IVec3 &gridCoord, const int coordBits, tcu::IVec3 &baseTexel,
53 tcu::IVec3 &texelGridOffset);
54 void calcTexelGridCoordRange(const tcu::Vec3 &unnormalizedCoordMin, const tcu::Vec3 &unnormalizedCoordMax,
55 const int coordBits, tcu::IVec3 &gridCoordMin, tcu::IVec3 &gridCoordMax);
56 void calcUnnormalizedCoordRange(const tcu::Vec4 &coord, const tcu::IVec3 &levelSize,
57 const tcu::FloatFormat &internalFormat, tcu::Vec3 &unnormalizedCoordMin,
58 tcu::Vec3 &unnormalizedCoordMax);
59 void calcCubemapFaceCoords(const tcu::Vec3 &r, const tcu::Vec3 &drdx, const tcu::Vec3 &drdy, const int faceNdx,
60 tcu::Vec2 &coordFace, tcu::Vec2 &dPdxFace, tcu::Vec2 &dPdyFace);
61 int calcCandidateCubemapFaces(const tcu::Vec3 &r);
62 int32_t wrapTexelCoord(const int32_t coord, const int size, const vk::VkSamplerAddressMode wrap);
63 void wrapCubemapEdge(const tcu::IVec2 &coord, const tcu::IVec2 &size, const int faceNdx, tcu::IVec2 &newCoord,
64 int &newFaceNdx);
65 void wrapCubemapCorner(const tcu::IVec2 &coord, const tcu::IVec2 &size, const int faceNdx, int &adjacentFace1,
66 int &adjacentFace2, tcu::IVec2 &cornerCoord0, tcu::IVec2 &cornerCoord1,
67 tcu::IVec2 &cornerCoord2);
68
69 void convertFormat(const void *pixelPtr, tcu::TextureFormat texFormat,
70 const std::vector<de::SharedPtr<tcu::FloatFormat>> &internalFormat, tcu::Vec4 &resultMin,
71 tcu::Vec4 &resultMax);
72
73 template <int Size>
isEqualRelEpsilon(const tcu::Vector<float,Size> & a,const tcu::Vector<float,Size> & b,const float epsilon)74 bool isEqualRelEpsilon(const tcu::Vector<float, Size> &a, const tcu::Vector<float, Size> &b, const float epsilon)
75 {
76 for (int compNdx = 0; compNdx < Size; ++compNdx)
77 {
78 if (!isEqualRelEpsilon(a[compNdx], b[compNdx], epsilon))
79 {
80 return false;
81 }
82 }
83
84 return true;
85 }
86
87 template <int Size>
isInRange(const tcu::Vector<float,Size> & v,const tcu::Vector<float,Size> & min,const tcu::Vector<float,Size> & max)88 bool isInRange(const tcu::Vector<float, Size> &v, const tcu::Vector<float, Size> &min,
89 const tcu::Vector<float, Size> &max)
90 {
91 for (int compNdx = 0; compNdx < Size; ++compNdx)
92 {
93 if (v[compNdx] < min[compNdx] || v[compNdx] > max[compNdx])
94 {
95 return false;
96 }
97 }
98
99 return true;
100 }
101
102 template <int Size>
floor(const tcu::Vector<float,Size> & v)103 tcu::Vector<float, Size> floor(const tcu::Vector<float, Size> &v)
104 {
105 tcu::Vector<float, Size> result;
106
107 for (int compNdx = 0; compNdx < Size; ++compNdx)
108 {
109 result[compNdx] = (float)deFloor(v[compNdx]);
110 }
111
112 return result;
113 }
114
115 template <int Size>
ceil(const tcu::Vector<float,Size> & v)116 tcu::Vector<float, Size> ceil(const tcu::Vector<float, Size> &v)
117 {
118 tcu::Vector<float, Size> result;
119
120 for (int compNdx = 0; compNdx < Size; ++compNdx)
121 {
122 result[compNdx] = (float)deCeil(v[compNdx]);
123 }
124
125 return result;
126 }
127
128 template <int Size>
abs(const tcu::Vector<float,Size> & v)129 tcu::Vector<float, Size> abs(const tcu::Vector<float, Size> &v)
130 {
131 tcu::Vector<float, Size> result;
132
133 for (int compNdx = 0; compNdx < Size; ++compNdx)
134 {
135 result[compNdx] = de::abs(v[compNdx]);
136 }
137
138 return result;
139 }
140
141 } // namespace util
142 } // namespace texture
143 } // namespace vkt
144
145 #endif // _VKTSAMPLEVERIFIERUTIL_HPP
146