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