blob: 56841a891f1481dda0a45ba6bba0856a4583ff79 [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"
20
21namespace sw
22{
23 struct Mipmap
24 {
Nicolas Capens8e8a7e82015-09-01 14:39:57 -040025 const void *buffer[6];
John Bauman66b8ab22014-05-06 15:57:45 -040026
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 Hetu95ac1872016-06-06 13:26:52 -040070 int baseLevel;
71 int maxLevel;
Alexis Hetu112d81f2016-06-07 12:36:35 -040072 float minLod;
73 float maxLod;
John Bauman66b8ab22014-05-06 15:57:45 -040074 };
75
76 enum SamplerType
77 {
78 SAMPLER_PIXEL,
79 SAMPLER_VERTEX
80 };
81
Nicolas Capensa0f4be82014-10-22 14:35:30 -040082 enum TextureType : unsigned int
John Bauman66b8ab22014-05-06 15:57:45 -040083 {
84 TEXTURE_NULL,
85 TEXTURE_2D,
86 TEXTURE_CUBE,
87 TEXTURE_3D,
Alexis Hetu8216de92015-04-15 11:45:56 -040088 TEXTURE_2D_ARRAY,
John Bauman66b8ab22014-05-06 15:57:45 -040089
Alexis Hetu8216de92015-04-15 11:45:56 -040090 TEXTURE_LAST = TEXTURE_2D_ARRAY
John Bauman66b8ab22014-05-06 15:57:45 -040091 };
92
Nicolas Capensa0f4be82014-10-22 14:35:30 -040093 enum FilterType : unsigned int
John Bauman66b8ab22014-05-06 15:57:45 -040094 {
95 FILTER_POINT,
96 FILTER_GATHER,
Alexis Hetuc4d04462015-12-10 08:42:02 -050097 FILTER_MIN_POINT_MAG_LINEAR,
98 FILTER_MIN_LINEAR_MAG_POINT,
John Bauman66b8ab22014-05-06 15:57:45 -040099 FILTER_LINEAR,
100 FILTER_ANISOTROPIC,
101
102 FILTER_LAST = FILTER_ANISOTROPIC
103 };
104
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400105 enum MipmapType : unsigned int
John Bauman66b8ab22014-05-06 15:57:45 -0400106 {
107 MIPMAP_NONE,
108 MIPMAP_POINT,
109 MIPMAP_LINEAR,
Nicolas Capens7bb62682016-02-08 11:30:56 -0500110
John Bauman66b8ab22014-05-06 15:57:45 -0400111 MIPMAP_LAST = MIPMAP_LINEAR
112 };
113
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400114 enum AddressingMode : unsigned int
John Bauman66b8ab22014-05-06 15:57:45 -0400115 {
116 ADDRESSING_WRAP,
117 ADDRESSING_CLAMP,
118 ADDRESSING_MIRROR,
119 ADDRESSING_MIRRORONCE,
120 ADDRESSING_BORDER,
Nicolas Capens7bb62682016-02-08 11:30:56 -0500121 ADDRESSING_LAYER,
Meng-Lin Wu2fce5822016-06-07 16:15:12 -0400122 ADDRESSING_TEXELFETCH,
John Bauman66b8ab22014-05-06 15:57:45 -0400123
Meng-Lin Wu2fce5822016-06-07 16:15:12 -0400124 ADDRESSING_LAST = ADDRESSING_TEXELFETCH
John Bauman66b8ab22014-05-06 15:57:45 -0400125 };
126
Alexis Hetu1d01aa32015-09-29 11:50:05 -0400127 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 Bauman66b8ab22014-05-06 15:57:45 -0400139 class Sampler
140 {
141 public:
142 struct State
143 {
144 State();
145
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400146 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 Hetu9f7d5622016-06-02 17:47:38 -0400153 bool hasNPOTTexture : 1;
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400154 bool sRGB : 1;
Alexis Hetu1d01aa32015-09-29 11:50:05 -0400155 SwizzleType swizzleR : BITS(SWIZZLE_LAST);
156 SwizzleType swizzleG : BITS(SWIZZLE_LAST);
157 SwizzleType swizzleB : BITS(SWIZZLE_LAST);
158 SwizzleType swizzleA : BITS(SWIZZLE_LAST);
John Bauman66b8ab22014-05-06 15:57:45 -0400159
160 #if PERF_PROFILE
Nicolas Capensa0f4be82014-10-22 14:35:30 -0400161 bool compressedFormat : 1;
John Bauman66b8ab22014-05-06 15:57:45 -0400162 #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 Hetu617a5d52014-11-13 10:56:20 -0500181 void setMaxAnisotropy(float maxAnisotropy);
Alexis Hetu1d01aa32015-09-29 11:50:05 -0400182 void setSwizzleR(SwizzleType swizzleR);
183 void setSwizzleG(SwizzleType swizzleG);
184 void setSwizzleB(SwizzleType swizzleB);
185 void setSwizzleA(SwizzleType swizzleA);
Alexis Hetu95ac1872016-06-06 13:26:52 -0400186 void setBaseLevel(int baseLevel);
187 void setMaxLevel(int maxLevel);
Alexis Hetu112d81f2016-06-07 12:36:35 -0400188 void setMinLod(float minLod);
189 void setMaxLod(float maxLod);
John Bauman66b8ab22014-05-06 15:57:45 -0400190
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 Hetu1d01aa32015-09-29 11:50:05 -0400223 SwizzleType swizzleR;
224 SwizzleType swizzleG;
225 SwizzleType swizzleB;
226 SwizzleType swizzleA;
John Bauman66b8ab22014-05-06 15:57:45 -0400227 Texture texture;
228 float exp2LOD;
229
230 static FilterType maximumTextureFilterQuality;
231 static MipmapType maximumMipmapFilterQuality;
232 };
233}
234
235#endif // sw_Sampler_hpp