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, 127 const SamplerParameters& samplerParams, 128 const SampleLookupSettings& sampleLookupSettings, 129 int coordBits, 130 int mipmapBits, 131 const std::vector<de::SharedPtr<tcu::FloatFormat>>& conversionPrecision, 132 const std::vector<de::SharedPtr<tcu::FloatFormat>>& filteringPrecision, 133 const std::vector<tcu::ConstPixelBufferAccess>& levels); 134 135 bool verifySample (const SampleArguments& args, 136 const tcu::Vec4& result) const; 137 138 bool verifySampleReport (const SampleArguments& args, 139 const tcu::Vec4& result, 140 std::string& report) const; 141 142 private: 143 144 bool verifySampleFiltered (const tcu::Vec4& result, 145 const tcu::IVec3& baseTexelHi, 146 const tcu::IVec3& baseTexelLo, 147 const tcu::IVec3& texelGridOffsetHi, 148 const tcu::IVec3& texelGridOffsetLo, 149 int layer, 150 int levelHi, 151 const tcu::Vec2& lodFracBounds, 152 vk::VkFilter filter, 153 vk::VkSamplerMipmapMode mipmapFilter, 154 std::ostream& report) const; 155 156 bool verifySampleTexelGridCoords (const SampleArguments& args, 157 const tcu::Vec4& result, 158 const tcu::IVec3& gridCoordHi, 159 const tcu::IVec3& gridCoordLo, 160 const tcu::Vec2& lodBounds, 161 int level, 162 vk::VkSamplerMipmapMode mipmapFilter, 163 std::ostream& report) const; 164 165 bool verifySampleMipmapLevel (const SampleArguments& args, 166 const tcu::Vec4& result, 167 const tcu::Vec4& coord, 168 const tcu::Vec2& lodFracBounds, 169 int level, 170 std::ostream& report) const; 171 172 bool verifySampleCubemapFace (const SampleArguments& args, 173 const tcu::Vec4& result, 174 const tcu::Vec4& coord, 175 const tcu::Vec4& dPdx, 176 const tcu::Vec4& dPdy, 177 int face, 178 std::ostream& report) const; 179 180 bool verifySampleImpl (const SampleArguments& args, 181 const tcu::Vec4& result, 182 std::ostream& report) const; 183 184 bool coordOutOfRange (const tcu::IVec3& coord, 185 int compNdx, 186 int level) const; 187 188 void fetchTexel (const tcu::IVec3& coordIn, 189 int layer, 190 int level, 191 vk::VkFilter filter, 192 tcu::Vec4& resultMin, 193 tcu::Vec4& resultMax) const; 194 195 void fetchTexelWrapped (const tcu::IVec3& coord, 196 int layer, 197 int level, 198 tcu::Vec4& resultMin, 199 tcu::Vec4& resultMax) const; 200 201 void getFilteredSample1D (const tcu::IVec3& texelBase, 202 float weight, 203 int layer, 204 int level, 205 tcu::Vec4& resultMin, 206 tcu::Vec4& resultMax) const; 207 208 void getFilteredSample2D (const tcu::IVec3& texelBase, 209 const tcu::Vec2& weights, 210 int layer, 211 int level, 212 tcu::Vec4& resultMin, 213 tcu::Vec4& resultMax) const; 214 215 void getFilteredSample3D (const tcu::IVec3& texelBase, 216 const tcu::Vec3& weights, 217 int layer, 218 int level, 219 tcu::Vec4& resultMin, 220 tcu::Vec4& resultMax) const; 221 222 void getFilteredSample (const tcu::IVec3& texelBase, 223 const tcu::Vec3& weights, 224 int layer, 225 int level, 226 tcu::Vec4& resultMin, 227 tcu::Vec4& resultMax) const; 228 229 void getMipmapStepBounds (const tcu::Vec2& lodFracBounds, 230 deInt32& stepMin, 231 deInt32& stepMax) const; 232 233 const ImageViewParameters& m_imParams; 234 const SamplerParameters& m_samplerParams; 235 const SampleLookupSettings& m_sampleLookupSettings; 236 237 const int m_coordBits; 238 const int m_mipmapBits; 239 const std::vector<de::SharedPtr<tcu::FloatFormat>> m_conversionPrecision; 240 const std::vector<de::SharedPtr<tcu::FloatFormat>> m_filteringPrecision; 241 242 const int m_unnormalizedDim; 243 244 const std::vector<tcu::ConstPixelBufferAccess>& m_levels; 245 }; 246 247 } // texture 248 } // vkt 249 250 #endif // _VKTSAMPLEVERIFIER_HPP 251