1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef sw_Sampler_hpp 16 #define sw_Sampler_hpp 17 18 #include "Device/Config.hpp" 19 #include "System/Types.hpp" 20 #include "Vulkan/VkFormat.hpp" 21 22 namespace vk { 23 class Image; 24 } 25 26 namespace sw { 27 28 struct Mipmap 29 { 30 const void *buffer; 31 32 short4 uHalf; 33 short4 vHalf; 34 short4 wHalf; 35 int4 width; 36 int4 height; 37 int4 depth; 38 short4 onePitchP; 39 int4 pitchP; 40 int4 sliceP; 41 int4 samplePitchP; 42 int4 sampleMax; 43 }; 44 45 struct Texture 46 { 47 Mipmap mipmap[MIPMAP_LEVELS]; 48 49 float4 widthWidthHeightHeight; 50 float4 width; 51 float4 height; 52 float4 depth; 53 }; 54 55 enum FilterType ENUM_UNDERLYING_TYPE_UNSIGNED_INT 56 { 57 FILTER_POINT, 58 FILTER_GATHER, 59 FILTER_MIN_POINT_MAG_LINEAR, 60 FILTER_MIN_LINEAR_MAG_POINT, 61 FILTER_LINEAR, 62 FILTER_ANISOTROPIC, 63 64 FILTER_LAST = FILTER_ANISOTROPIC 65 }; 66 67 enum MipmapType ENUM_UNDERLYING_TYPE_UNSIGNED_INT 68 { 69 MIPMAP_NONE, 70 MIPMAP_POINT, 71 MIPMAP_LINEAR, 72 73 MIPMAP_LAST = MIPMAP_LINEAR 74 }; 75 76 enum AddressingMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT 77 { 78 ADDRESSING_UNUSED, 79 ADDRESSING_WRAP, 80 ADDRESSING_CLAMP, 81 ADDRESSING_MIRROR, 82 ADDRESSING_MIRRORONCE, 83 ADDRESSING_BORDER, // Single color 84 ADDRESSING_SEAMLESS, // Border of pixels 85 ADDRESSING_CUBEFACE, // Cube face layer 86 ADDRESSING_TEXELFETCH, 87 88 ADDRESSING_LAST = ADDRESSING_TEXELFETCH 89 }; 90 91 struct Sampler 92 { 93 VkImageViewType textureType; 94 vk::Format textureFormat; 95 FilterType textureFilter; 96 AddressingMode addressingModeU; 97 AddressingMode addressingModeV; 98 AddressingMode addressingModeW; 99 MipmapType mipmapFilter; 100 VkComponentMapping swizzle; 101 int gatherComponent; 102 bool highPrecisionFiltering; 103 bool compareEnable; 104 VkCompareOp compareOp; 105 VkBorderColor border; 106 bool unnormalizedCoordinates; 107 108 VkSamplerYcbcrModelConversion ycbcrModel; 109 bool studioSwing; // Narrow range 110 bool swappedChroma; // Cb/Cr components in reverse order 111 112 float mipLodBias = 0.0f; 113 float maxAnisotropy = 0.0f; 114 float minLod = 0.0f; 115 float maxLod = 0.0f; 116 is1Dsw::Sampler117 bool is1D() const 118 { 119 switch(textureType) 120 { 121 case VK_IMAGE_VIEW_TYPE_1D: 122 case VK_IMAGE_VIEW_TYPE_1D_ARRAY: 123 return true; 124 case VK_IMAGE_VIEW_TYPE_2D: 125 case VK_IMAGE_VIEW_TYPE_3D: 126 case VK_IMAGE_VIEW_TYPE_CUBE: 127 case VK_IMAGE_VIEW_TYPE_2D_ARRAY: 128 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: 129 return false; 130 default: 131 UNSUPPORTED("VkImageViewType %d", (int)textureType); 132 } 133 134 return false; 135 } 136 is2Dsw::Sampler137 bool is2D() const 138 { 139 switch(textureType) 140 { 141 case VK_IMAGE_VIEW_TYPE_2D: 142 case VK_IMAGE_VIEW_TYPE_2D_ARRAY: 143 return true; 144 case VK_IMAGE_VIEW_TYPE_1D: 145 case VK_IMAGE_VIEW_TYPE_3D: 146 case VK_IMAGE_VIEW_TYPE_CUBE: 147 case VK_IMAGE_VIEW_TYPE_1D_ARRAY: 148 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: 149 return false; 150 default: 151 UNSUPPORTED("VkImageViewType %d", (int)textureType); 152 } 153 154 return false; 155 } 156 is3Dsw::Sampler157 bool is3D() const 158 { 159 switch(textureType) 160 { 161 case VK_IMAGE_VIEW_TYPE_3D: 162 return true; 163 case VK_IMAGE_VIEW_TYPE_1D: 164 case VK_IMAGE_VIEW_TYPE_2D: 165 case VK_IMAGE_VIEW_TYPE_CUBE: 166 case VK_IMAGE_VIEW_TYPE_1D_ARRAY: 167 case VK_IMAGE_VIEW_TYPE_2D_ARRAY: 168 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: 169 return false; 170 default: 171 UNSUPPORTED("VkImageViewType %d", (int)textureType); 172 } 173 174 return false; 175 } 176 isCubesw::Sampler177 bool isCube() const 178 { 179 switch(textureType) 180 { 181 case VK_IMAGE_VIEW_TYPE_CUBE: 182 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: 183 return true; 184 case VK_IMAGE_VIEW_TYPE_1D: 185 case VK_IMAGE_VIEW_TYPE_2D: 186 case VK_IMAGE_VIEW_TYPE_3D: 187 case VK_IMAGE_VIEW_TYPE_1D_ARRAY: 188 case VK_IMAGE_VIEW_TYPE_2D_ARRAY: 189 return false; 190 default: 191 UNSUPPORTED("VkImageViewType %d", (int)textureType); 192 } 193 194 return false; 195 } 196 isArrayedsw::Sampler197 bool isArrayed() const 198 { 199 switch(textureType) 200 { 201 case VK_IMAGE_VIEW_TYPE_1D_ARRAY: 202 case VK_IMAGE_VIEW_TYPE_2D_ARRAY: 203 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: 204 return true; 205 case VK_IMAGE_VIEW_TYPE_1D: 206 case VK_IMAGE_VIEW_TYPE_2D: 207 case VK_IMAGE_VIEW_TYPE_3D: 208 case VK_IMAGE_VIEW_TYPE_CUBE: 209 return false; 210 default: 211 UNSUPPORTED("VkImageViewType %d", (int)textureType); 212 } 213 214 return false; 215 } 216 }; 217 218 } // namespace sw 219 220 #endif // sw_Sampler_hpp 221