xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/texture/vktSampleVerifier.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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 #include "deSharedPtr.hpp"
30 
31 #include "tcuFloatFormat.hpp"
32 #include "tcuTexture.hpp"
33 #include "tcuVector.hpp"
34 
35 #include <iostream>
36 #include <string>
37 #include <vector>
38 
39 namespace vkt
40 {
41 namespace texture
42 {
43 
44 struct SampleArguments
45 {
46     tcu::Vec4 coord;
47     tcu::Vec4 dPdx;
48     tcu::Vec4 dPdy;
49     float layer;
50     float lod;
51     float lodBias;
52     float dRef;
53 };
54 
55 enum LookupLodMode
56 {
57     LOOKUP_LOD_MODE_DERIVATIVES = 0,
58     LOOKUP_LOD_MODE_LOD,
59 
60     LOOKUP_LOD_MODE_LAST
61 };
62 
63 struct SampleLookupSettings
64 {
65     LookupLodMode lookupLodMode;
66     bool hasLodBias;
67     bool isProjective;
68 };
69 
70 enum WrappingMode
71 {
72     WRAPPING_MODE_REPEAT = 0,
73     WRAPPING_MODE_MIRRORED_REPEAT,
74     WRAPPING_MODE_CLAMP_TO_EDGE,
75     WRAPPING_MODE_CLAMP_TO_BORDER,
76     WRAPPING_MODE_MIRROR_CLAMP_TO_EDGE,
77 
78     WRAPPING_MODE_LAST
79 };
80 
81 struct SamplerParameters
82 {
83     vk::VkFilter magFilter;
84     vk::VkFilter minFilter;
85     vk::VkSamplerMipmapMode mipmapFilter;
86 
87     vk::VkSamplerAddressMode wrappingModeU;
88     vk::VkSamplerAddressMode wrappingModeV;
89     vk::VkSamplerAddressMode wrappingModeW;
90 
91     vk::VkBorderColor borderColor;
92 
93     float lodBias;
94     float minLod;
95     float maxLod;
96 
97     bool isUnnormalized;
98     bool isCompare;
99 };
100 
101 enum ImgDim
102 {
103     IMG_DIM_INVALID = 0,
104     IMG_DIM_1D,
105     IMG_DIM_2D,
106     IMG_DIM_3D,
107     IMG_DIM_CUBE,
108 
109     IMG_DIM_LAST
110 };
111 
112 struct ImageViewParameters
113 {
114     ImgDim dim;
115     vk::VkFormat format;
116     tcu::IVec3 size;
117     int levels;
118 
119     bool isArrayed;
120     int arrayLayers;
121 };
122 
123 class SampleVerifier
124 {
125 public:
126     SampleVerifier(const ImageViewParameters &imParams, const SamplerParameters &samplerParams,
127                    const SampleLookupSettings &sampleLookupSettings, int coordBits, int mipmapBits,
128                    const std::vector<de::SharedPtr<tcu::FloatFormat>> &conversionPrecision,
129                    const std::vector<de::SharedPtr<tcu::FloatFormat>> &filteringPrecision,
130                    const std::vector<tcu::ConstPixelBufferAccess> &levels);
131 
132     bool verifySample(const SampleArguments &args, const tcu::Vec4 &result) const;
133 
134     bool verifySampleReport(const SampleArguments &args, const tcu::Vec4 &result, std::string &report) const;
135 
136 private:
137     bool verifySampleFiltered(const tcu::Vec4 &result, const tcu::IVec3 &baseTexelHi, const tcu::IVec3 &baseTexelLo,
138                               const tcu::IVec3 &texelGridOffsetHi, const tcu::IVec3 &texelGridOffsetLo, int layer,
139                               int levelHi, const tcu::Vec2 &lodFracBounds, vk::VkFilter filter,
140                               vk::VkSamplerMipmapMode mipmapFilter, std::ostream &report) const;
141 
142     bool verifySampleTexelGridCoords(const SampleArguments &args, const tcu::Vec4 &result,
143                                      const tcu::IVec3 &gridCoordHi, const tcu::IVec3 &gridCoordLo,
144                                      const tcu::Vec2 &lodBounds, int level, vk::VkSamplerMipmapMode mipmapFilter,
145                                      std::ostream &report) const;
146 
147     bool verifySampleMipmapLevel(const SampleArguments &args, const tcu::Vec4 &result, const tcu::Vec4 &coord,
148                                  const tcu::Vec2 &lodFracBounds, int level, std::ostream &report) const;
149 
150     bool verifySampleCubemapFace(const SampleArguments &args, const tcu::Vec4 &result, const tcu::Vec4 &coord,
151                                  const tcu::Vec4 &dPdx, const tcu::Vec4 &dPdy, int face, std::ostream &report) const;
152 
153     bool verifySampleImpl(const SampleArguments &args, const tcu::Vec4 &result, std::ostream &report) const;
154 
155     bool coordOutOfRange(const tcu::IVec3 &coord, int compNdx, int level) const;
156 
157     void fetchTexel(const tcu::IVec3 &coordIn, int layer, int level, vk::VkFilter filter, tcu::Vec4 &resultMin,
158                     tcu::Vec4 &resultMax) const;
159 
160     void fetchTexelWrapped(const tcu::IVec3 &coord, int layer, int level, tcu::Vec4 &resultMin,
161                            tcu::Vec4 &resultMax) const;
162 
163     void getFilteredSample1D(const tcu::IVec3 &texelBase, float weight, int layer, int level, tcu::Vec4 &resultMin,
164                              tcu::Vec4 &resultMax) const;
165 
166     void getFilteredSample2D(const tcu::IVec3 &texelBase, const tcu::Vec2 &weights, int layer, int level,
167                              tcu::Vec4 &resultMin, tcu::Vec4 &resultMax) const;
168 
169     void getFilteredSample3D(const tcu::IVec3 &texelBase, const tcu::Vec3 &weights, int layer, int level,
170                              tcu::Vec4 &resultMin, tcu::Vec4 &resultMax) const;
171 
172     void getFilteredSample(const tcu::IVec3 &texelBase, const tcu::Vec3 &weights, int layer, int level,
173                            tcu::Vec4 &resultMin, tcu::Vec4 &resultMax) const;
174 
175     void getMipmapStepBounds(const tcu::Vec2 &lodFracBounds, int32_t &stepMin, int32_t &stepMax) const;
176 
177     const ImageViewParameters &m_imParams;
178     const SamplerParameters &m_samplerParams;
179     const SampleLookupSettings &m_sampleLookupSettings;
180 
181     const int m_coordBits;
182     const int m_mipmapBits;
183     const std::vector<de::SharedPtr<tcu::FloatFormat>> m_conversionPrecision;
184     const std::vector<de::SharedPtr<tcu::FloatFormat>> m_filteringPrecision;
185 
186     const int m_unnormalizedDim;
187 
188     const std::vector<tcu::ConstPixelBufferAccess> &m_levels;
189 };
190 
191 } // namespace texture
192 } // namespace vkt
193 
194 #endif // _VKTSAMPLEVERIFIER_HPP
195