Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
| 15 | #ifndef sw_Sampler_hpp |
| 16 | #define sw_Sampler_hpp |
| 17 | |
| 18 | #include "Main/Config.hpp" |
| 19 | #include "Renderer/Surface.hpp" |
Nicolas Capens | 28d5a26 | 2017-03-09 15:32:31 -0500 | [diff] [blame] | 20 | #include "Common/Types.hpp" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 21 | |
| 22 | namespace sw |
| 23 | { |
| 24 | struct Mipmap |
| 25 | { |
Nicolas Capens | 8e8a7e8 | 2015-09-01 14:39:57 -0400 | [diff] [blame] | 26 | const void *buffer[6]; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 27 | |
Nicolas Capens | 7798051 | 2016-12-02 14:22:32 -0500 | [diff] [blame] | 28 | float4 fWidth; |
| 29 | float4 fHeight; |
| 30 | float4 fDepth; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 31 | |
| 32 | short uHalf[4]; |
| 33 | short vHalf[4]; |
| 34 | short wHalf[4]; |
| 35 | short width[4]; |
| 36 | short height[4]; |
| 37 | short depth[4]; |
| 38 | short onePitchP[4]; |
Alexis Hetu | 75a6185 | 2017-07-14 14:17:14 -0400 | [diff] [blame] | 39 | int4 pitchP; |
| 40 | int4 sliceP; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | struct Texture |
| 44 | { |
| 45 | Mipmap mipmap[MIPMAP_LEVELS]; |
| 46 | |
| 47 | float LOD; |
| 48 | float4 widthHeightLOD; |
| 49 | float4 widthLOD; |
| 50 | float4 heightLOD; |
| 51 | float4 depthLOD; |
| 52 | |
| 53 | word4 borderColor4[4]; |
| 54 | float4 borderColorF[4]; |
| 55 | float maxAnisotropy; |
Alexis Hetu | 95ac187 | 2016-06-06 13:26:52 -0400 | [diff] [blame] | 56 | int baseLevel; |
| 57 | int maxLevel; |
Alexis Hetu | 112d81f | 2016-06-07 12:36:35 -0400 | [diff] [blame] | 58 | float minLod; |
| 59 | float maxLod; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | enum SamplerType |
| 63 | { |
| 64 | SAMPLER_PIXEL, |
| 65 | SAMPLER_VERTEX |
| 66 | }; |
| 67 | |
Nicolas Capens | 28d5a26 | 2017-03-09 15:32:31 -0500 | [diff] [blame] | 68 | enum TextureType ENUM_UNDERLYING_TYPE_UNSIGNED_INT |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 69 | { |
| 70 | TEXTURE_NULL, |
| 71 | TEXTURE_2D, |
Alexis Hetu | c0632c9 | 2018-03-02 15:10:16 -0500 | [diff] [blame] | 72 | TEXTURE_RECTANGLE, |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 73 | TEXTURE_CUBE, |
| 74 | TEXTURE_3D, |
Alexis Hetu | 8216de9 | 2015-04-15 11:45:56 -0400 | [diff] [blame] | 75 | TEXTURE_2D_ARRAY, |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 76 | |
Alexis Hetu | 8216de9 | 2015-04-15 11:45:56 -0400 | [diff] [blame] | 77 | TEXTURE_LAST = TEXTURE_2D_ARRAY |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 78 | }; |
| 79 | |
Nicolas Capens | 28d5a26 | 2017-03-09 15:32:31 -0500 | [diff] [blame] | 80 | enum FilterType ENUM_UNDERLYING_TYPE_UNSIGNED_INT |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 81 | { |
| 82 | FILTER_POINT, |
| 83 | FILTER_GATHER, |
Alexis Hetu | c4d0446 | 2015-12-10 08:42:02 -0500 | [diff] [blame] | 84 | FILTER_MIN_POINT_MAG_LINEAR, |
| 85 | FILTER_MIN_LINEAR_MAG_POINT, |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 86 | FILTER_LINEAR, |
| 87 | FILTER_ANISOTROPIC, |
| 88 | |
| 89 | FILTER_LAST = FILTER_ANISOTROPIC |
| 90 | }; |
| 91 | |
Nicolas Capens | 28d5a26 | 2017-03-09 15:32:31 -0500 | [diff] [blame] | 92 | enum MipmapType ENUM_UNDERLYING_TYPE_UNSIGNED_INT |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 93 | { |
| 94 | MIPMAP_NONE, |
| 95 | MIPMAP_POINT, |
| 96 | MIPMAP_LINEAR, |
Nicolas Capens | 7bb6268 | 2016-02-08 11:30:56 -0500 | [diff] [blame] | 97 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 98 | MIPMAP_LAST = MIPMAP_LINEAR |
| 99 | }; |
| 100 | |
Nicolas Capens | 28d5a26 | 2017-03-09 15:32:31 -0500 | [diff] [blame] | 101 | enum AddressingMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 102 | { |
| 103 | ADDRESSING_WRAP, |
| 104 | ADDRESSING_CLAMP, |
| 105 | ADDRESSING_MIRROR, |
| 106 | ADDRESSING_MIRRORONCE, |
Nicolas Capens | d0f5d39 | 2017-11-28 15:54:59 -0500 | [diff] [blame] | 107 | ADDRESSING_BORDER, // Single color |
| 108 | ADDRESSING_SEAMLESS, // Border of pixels |
Nicolas Capens | 7bb6268 | 2016-02-08 11:30:56 -0500 | [diff] [blame] | 109 | ADDRESSING_LAYER, |
Meng-Lin Wu | 2fce582 | 2016-06-07 16:15:12 -0400 | [diff] [blame] | 110 | ADDRESSING_TEXELFETCH, |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 111 | |
Meng-Lin Wu | 2fce582 | 2016-06-07 16:15:12 -0400 | [diff] [blame] | 112 | ADDRESSING_LAST = ADDRESSING_TEXELFETCH |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 113 | }; |
| 114 | |
Nicolas Capens | f878d50 | 2017-11-06 15:29:46 -0500 | [diff] [blame] | 115 | enum CompareFunc ENUM_UNDERLYING_TYPE_UNSIGNED_INT |
| 116 | { |
| 117 | COMPARE_BYPASS, |
| 118 | COMPARE_LESSEQUAL, |
| 119 | COMPARE_GREATEREQUAL, |
| 120 | COMPARE_LESS, |
| 121 | COMPARE_GREATER, |
| 122 | COMPARE_EQUAL, |
| 123 | COMPARE_NOTEQUAL, |
| 124 | COMPARE_ALWAYS, |
| 125 | COMPARE_NEVER, |
| 126 | |
| 127 | COMPARE_LAST = COMPARE_NEVER |
| 128 | }; |
| 129 | |
Nicolas Capens | 28d5a26 | 2017-03-09 15:32:31 -0500 | [diff] [blame] | 130 | enum SwizzleType ENUM_UNDERLYING_TYPE_UNSIGNED_INT |
Alexis Hetu | 1d01aa3 | 2015-09-29 11:50:05 -0400 | [diff] [blame] | 131 | { |
| 132 | SWIZZLE_RED, |
| 133 | SWIZZLE_GREEN, |
| 134 | SWIZZLE_BLUE, |
| 135 | SWIZZLE_ALPHA, |
| 136 | SWIZZLE_ZERO, |
| 137 | SWIZZLE_ONE, |
| 138 | |
| 139 | SWIZZLE_LAST = SWIZZLE_ONE |
| 140 | }; |
| 141 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 142 | class Sampler |
| 143 | { |
| 144 | public: |
| 145 | struct State |
| 146 | { |
| 147 | State(); |
| 148 | |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 149 | TextureType textureType : BITS(TEXTURE_LAST); |
| 150 | Format textureFormat : BITS(FORMAT_LAST); |
| 151 | FilterType textureFilter : BITS(FILTER_LAST); |
| 152 | AddressingMode addressingModeU : BITS(ADDRESSING_LAST); |
| 153 | AddressingMode addressingModeV : BITS(ADDRESSING_LAST); |
| 154 | AddressingMode addressingModeW : BITS(ADDRESSING_LAST); |
| 155 | MipmapType mipmapFilter : BITS(FILTER_LAST); |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 156 | bool sRGB : 1; |
Alexis Hetu | 1d01aa3 | 2015-09-29 11:50:05 -0400 | [diff] [blame] | 157 | SwizzleType swizzleR : BITS(SWIZZLE_LAST); |
| 158 | SwizzleType swizzleG : BITS(SWIZZLE_LAST); |
| 159 | SwizzleType swizzleB : BITS(SWIZZLE_LAST); |
| 160 | SwizzleType swizzleA : BITS(SWIZZLE_LAST); |
Alexis Hetu | 010a464 | 2017-07-18 14:33:04 -0400 | [diff] [blame] | 161 | bool highPrecisionFiltering : 1; |
Nicolas Capens | f878d50 | 2017-11-06 15:29:46 -0500 | [diff] [blame] | 162 | CompareFunc compare : BITS(COMPARE_LAST); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 163 | |
| 164 | #if PERF_PROFILE |
Nicolas Capens | a0f4be8 | 2014-10-22 14:35:30 -0400 | [diff] [blame] | 165 | bool compressedFormat : 1; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 166 | #endif |
| 167 | }; |
| 168 | |
| 169 | Sampler(); |
| 170 | |
| 171 | ~Sampler(); |
| 172 | |
| 173 | State samplerState() const; |
| 174 | |
| 175 | void setTextureLevel(int face, int level, Surface *surface, TextureType type); |
| 176 | |
| 177 | void setTextureFilter(FilterType textureFilter); |
| 178 | void setMipmapFilter(MipmapType mipmapFilter); |
| 179 | void setGatherEnable(bool enable); |
| 180 | void setAddressingModeU(AddressingMode addressingMode); |
| 181 | void setAddressingModeV(AddressingMode addressingMode); |
| 182 | void setAddressingModeW(AddressingMode addressingMode); |
| 183 | void setReadSRGB(bool sRGB); |
| 184 | void setBorderColor(const Color<float> &borderColor); |
Alexis Hetu | 617a5d5 | 2014-11-13 10:56:20 -0500 | [diff] [blame] | 185 | void setMaxAnisotropy(float maxAnisotropy); |
Alexis Hetu | 010a464 | 2017-07-18 14:33:04 -0400 | [diff] [blame] | 186 | void setHighPrecisionFiltering(bool highPrecisionFiltering); |
Alexis Hetu | 1d01aa3 | 2015-09-29 11:50:05 -0400 | [diff] [blame] | 187 | void setSwizzleR(SwizzleType swizzleR); |
| 188 | void setSwizzleG(SwizzleType swizzleG); |
| 189 | void setSwizzleB(SwizzleType swizzleB); |
| 190 | void setSwizzleA(SwizzleType swizzleA); |
Nicolas Capens | f878d50 | 2017-11-06 15:29:46 -0500 | [diff] [blame] | 191 | void setCompareFunc(CompareFunc compare); |
Alexis Hetu | 95ac187 | 2016-06-06 13:26:52 -0400 | [diff] [blame] | 192 | void setBaseLevel(int baseLevel); |
| 193 | void setMaxLevel(int maxLevel); |
Alexis Hetu | 112d81f | 2016-06-07 12:36:35 -0400 | [diff] [blame] | 194 | void setMinLod(float minLod); |
| 195 | void setMaxLod(float maxLod); |
Cody Schuffelen | 124c81a | 2019-03-15 15:21:34 -0700 | [diff] [blame] | 196 | void setSyncRequired(bool isSincRequired); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 197 | |
| 198 | static void setFilterQuality(FilterType maximumFilterQuality); |
| 199 | static void setMipmapQuality(MipmapType maximumFilterQuality); |
| 200 | void setMipmapLOD(float lod); |
| 201 | |
| 202 | bool hasTexture() const; |
| 203 | bool hasUnsignedTexture() const; |
| 204 | bool hasCubeTexture() const; |
| 205 | bool hasVolumeTexture() const; |
Cody Schuffelen | 124c81a | 2019-03-15 15:21:34 -0700 | [diff] [blame] | 206 | bool requiresSync() const; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 207 | |
| 208 | const Texture &getTextureData(); |
| 209 | |
| 210 | private: |
| 211 | MipmapType mipmapFilter() const; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 212 | TextureType getTextureType() const; |
| 213 | FilterType getTextureFilter() const; |
| 214 | AddressingMode getAddressingModeU() const; |
| 215 | AddressingMode getAddressingModeV() const; |
| 216 | AddressingMode getAddressingModeW() const; |
Nicolas Capens | f878d50 | 2017-11-06 15:29:46 -0500 | [diff] [blame] | 217 | CompareFunc getCompareFunc() const; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 218 | |
| 219 | Format externalTextureFormat; |
| 220 | Format internalTextureFormat; |
| 221 | TextureType textureType; |
| 222 | |
| 223 | FilterType textureFilter; |
| 224 | AddressingMode addressingModeU; |
| 225 | AddressingMode addressingModeV; |
| 226 | AddressingMode addressingModeW; |
| 227 | MipmapType mipmapFilterState; |
| 228 | bool sRGB; |
| 229 | bool gather; |
Alexis Hetu | 010a464 | 2017-07-18 14:33:04 -0400 | [diff] [blame] | 230 | bool highPrecisionFiltering; |
Cody Schuffelen | 124c81a | 2019-03-15 15:21:34 -0700 | [diff] [blame] | 231 | bool syncRequired; |
Nicolas Capens | d0f5d39 | 2017-11-28 15:54:59 -0500 | [diff] [blame] | 232 | int border; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 233 | |
Alexis Hetu | 1d01aa3 | 2015-09-29 11:50:05 -0400 | [diff] [blame] | 234 | SwizzleType swizzleR; |
| 235 | SwizzleType swizzleG; |
| 236 | SwizzleType swizzleB; |
| 237 | SwizzleType swizzleA; |
Nicolas Capens | f878d50 | 2017-11-06 15:29:46 -0500 | [diff] [blame] | 238 | CompareFunc compare; |
| 239 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 240 | Texture texture; |
| 241 | float exp2LOD; |
| 242 | |
| 243 | static FilterType maximumTextureFilterQuality; |
| 244 | static MipmapType maximumMipmapFilterQuality; |
| 245 | }; |
| 246 | } |
| 247 | |
| 248 | #endif // sw_Sampler_hpp |