blob: af225c50584fdbc42b7f64cfbe652be2bcbbecfe [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// 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 Bauman66b8ab22014-05-06 15:57:45 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
John Bauman66b8ab22014-05-06 15:57:45 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// 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 Bauman66b8ab22014-05-06 15:57:45 -040014
15#ifndef sw_Sampler_hpp
16#define sw_Sampler_hpp
17
18#include "Main/Config.hpp"
19#include "Renderer/Surface.hpp"
Nicolas Capens28d5a262017-03-09 15:32:31 -050020#include "Common/Types.hpp"
John Bauman66b8ab22014-05-06 15:57:45 -040021
22namespace sw
23{
24 struct Mipmap
25 {
Nicolas Capens8e8a7e82015-09-01 14:39:57 -040026 const void *buffer[6];
John Bauman66b8ab22014-05-06 15:57:45 -040027
Nicolas Capens77980512016-12-02 14:22:32 -050028 float4 fWidth;
29 float4 fHeight;
30 float4 fDepth;
John Bauman66b8ab22014-05-06 15:57:45 -040031
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 Hetu75a61852017-07-14 14:17:14 -040039 int4 pitchP;
40 int4 sliceP;
John Bauman66b8ab22014-05-06 15:57:45 -040041 };
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 Hetu95ac1872016-06-06 13:26:52 -040056 int baseLevel;
57 int maxLevel;
Alexis Hetu112d81f2016-06-07 12:36:35 -040058 float minLod;
59 float maxLod;
John Bauman66b8ab22014-05-06 15:57:45 -040060 };
61
62 enum SamplerType
63 {
64 SAMPLER_PIXEL,
65 SAMPLER_VERTEX
66 };
67
Nicolas Capens28d5a262017-03-09 15:32:31 -050068 enum TextureType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
John Bauman66b8ab22014-05-06 15:57:45 -040069 {
70 TEXTURE_NULL,
71 TEXTURE_2D,
Alexis Hetuc0632c92018-03-02 15:10:16 -050072 TEXTURE_RECTANGLE,
John Bauman66b8ab22014-05-06 15:57:45 -040073 TEXTURE_CUBE,
74 TEXTURE_3D,
Alexis Hetu8216de92015-04-15 11:45:56 -040075 TEXTURE_2D_ARRAY,
John Bauman66b8ab22014-05-06 15:57:45 -040076
Alexis Hetu8216de92015-04-15 11:45:56 -040077 TEXTURE_LAST = TEXTURE_2D_ARRAY
John Bauman66b8ab22014-05-06 15:57:45 -040078 };
79
Nicolas Capens28d5a262017-03-09 15:32:31 -050080 enum FilterType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
John Bauman66b8ab22014-05-06 15:57:45 -040081 {
82 FILTER_POINT,
83 FILTER_GATHER,
Alexis Hetuc4d04462015-12-10 08:42:02 -050084 FILTER_MIN_POINT_MAG_LINEAR,
85 FILTER_MIN_LINEAR_MAG_POINT,
John Bauman66b8ab22014-05-06 15:57:45 -040086 FILTER_LINEAR,
87 FILTER_ANISOTROPIC,
88
89 FILTER_LAST = FILTER_ANISOTROPIC
90 };
91
Nicolas Capens28d5a262017-03-09 15:32:31 -050092 enum MipmapType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
John Bauman66b8ab22014-05-06 15:57:45 -040093 {
94 MIPMAP_NONE,
95 MIPMAP_POINT,
96 MIPMAP_LINEAR,
Nicolas Capens7bb62682016-02-08 11:30:56 -050097
John Bauman66b8ab22014-05-06 15:57:45 -040098 MIPMAP_LAST = MIPMAP_LINEAR
99 };
100
Nicolas Capens28d5a262017-03-09 15:32:31 -0500101 enum AddressingMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT
John Bauman66b8ab22014-05-06 15:57:45 -0400102 {
103 ADDRESSING_WRAP,
104 ADDRESSING_CLAMP,
105 ADDRESSING_MIRROR,
106 ADDRESSING_MIRRORONCE,
Nicolas Capensd0f5d392017-11-28 15:54:59 -0500107 ADDRESSING_BORDER, // Single color
108 ADDRESSING_SEAMLESS, // Border of pixels
Nicolas Capens7bb62682016-02-08 11:30:56 -0500109 ADDRESSING_LAYER,
Meng-Lin Wu2fce5822016-06-07 16:15:12 -0400110 ADDRESSING_TEXELFETCH,
John Bauman66b8ab22014-05-06 15:57:45 -0400111
Meng-Lin Wu2fce5822016-06-07 16:15:12 -0400112 ADDRESSING_LAST = ADDRESSING_TEXELFETCH
John Bauman66b8ab22014-05-06 15:57:45 -0400113 };
114
Nicolas Capensf878d502017-11-06 15:29:46 -0500115 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 Capens28d5a262017-03-09 15:32:31 -0500130 enum SwizzleType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
Alexis Hetu1d01aa32015-09-29 11:50:05 -0400131 {
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 Bauman66b8ab22014-05-06 15:57:45 -0400142 class Sampler
143 {
144 public:
145 struct State
146 {
147 State();
148
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400149 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 Capensa0f4be82014-10-22 14:35:30 -0400156 bool sRGB : 1;
Alexis Hetu1d01aa32015-09-29 11:50:05 -0400157 SwizzleType swizzleR : BITS(SWIZZLE_LAST);
158 SwizzleType swizzleG : BITS(SWIZZLE_LAST);
159 SwizzleType swizzleB : BITS(SWIZZLE_LAST);
160 SwizzleType swizzleA : BITS(SWIZZLE_LAST);
Alexis Hetu010a4642017-07-18 14:33:04 -0400161 bool highPrecisionFiltering : 1;
Nicolas Capensf878d502017-11-06 15:29:46 -0500162 CompareFunc compare : BITS(COMPARE_LAST);
John Bauman66b8ab22014-05-06 15:57:45 -0400163
164 #if PERF_PROFILE
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400165 bool compressedFormat : 1;
John Bauman66b8ab22014-05-06 15:57:45 -0400166 #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 Hetu617a5d52014-11-13 10:56:20 -0500185 void setMaxAnisotropy(float maxAnisotropy);
Alexis Hetu010a4642017-07-18 14:33:04 -0400186 void setHighPrecisionFiltering(bool highPrecisionFiltering);
Alexis Hetu1d01aa32015-09-29 11:50:05 -0400187 void setSwizzleR(SwizzleType swizzleR);
188 void setSwizzleG(SwizzleType swizzleG);
189 void setSwizzleB(SwizzleType swizzleB);
190 void setSwizzleA(SwizzleType swizzleA);
Nicolas Capensf878d502017-11-06 15:29:46 -0500191 void setCompareFunc(CompareFunc compare);
Alexis Hetu95ac1872016-06-06 13:26:52 -0400192 void setBaseLevel(int baseLevel);
193 void setMaxLevel(int maxLevel);
Alexis Hetu112d81f2016-06-07 12:36:35 -0400194 void setMinLod(float minLod);
195 void setMaxLod(float maxLod);
Cody Schuffelen124c81a2019-03-15 15:21:34 -0700196 void setSyncRequired(bool isSincRequired);
John Bauman66b8ab22014-05-06 15:57:45 -0400197
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 Schuffelen124c81a2019-03-15 15:21:34 -0700206 bool requiresSync() const;
John Bauman66b8ab22014-05-06 15:57:45 -0400207
208 const Texture &getTextureData();
209
210 private:
211 MipmapType mipmapFilter() const;
John Bauman66b8ab22014-05-06 15:57:45 -0400212 TextureType getTextureType() const;
213 FilterType getTextureFilter() const;
214 AddressingMode getAddressingModeU() const;
215 AddressingMode getAddressingModeV() const;
216 AddressingMode getAddressingModeW() const;
Nicolas Capensf878d502017-11-06 15:29:46 -0500217 CompareFunc getCompareFunc() const;
John Bauman66b8ab22014-05-06 15:57:45 -0400218
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 Hetu010a4642017-07-18 14:33:04 -0400230 bool highPrecisionFiltering;
Cody Schuffelen124c81a2019-03-15 15:21:34 -0700231 bool syncRequired;
Nicolas Capensd0f5d392017-11-28 15:54:59 -0500232 int border;
John Bauman66b8ab22014-05-06 15:57:45 -0400233
Alexis Hetu1d01aa32015-09-29 11:50:05 -0400234 SwizzleType swizzleR;
235 SwizzleType swizzleG;
236 SwizzleType swizzleB;
237 SwizzleType swizzleA;
Nicolas Capensf878d502017-11-06 15:29:46 -0500238 CompareFunc compare;
239
John Bauman66b8ab22014-05-06 15:57:45 -0400240 Texture texture;
241 float exp2LOD;
242
243 static FilterType maximumTextureFilterQuality;
244 static MipmapType maximumMipmapFilterQuality;
245 };
246}
247
248#endif // sw_Sampler_hpp