blob: f86db8582f892c4916807e7bab7f2ca75fe86c98 [file] [log] [blame]
Nicolas Capens68a82382018-10-02 13:16:55 -04001// 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
Alexis Hetu696926d2019-03-18 11:30:01 -040018#include "Device/Color.hpp"
Nicolas Capens1d8c8db2018-11-05 16:30:42 -050019#include "Device/Config.hpp"
Nicolas Capens1d8c8db2018-11-05 16:30:42 -050020#include "System/Types.hpp"
Alexis Hetu696926d2019-03-18 11:30:01 -040021#include "Vulkan/VkFormat.h"
22
23namespace vk
24{
25 class Image;
26}
Nicolas Capens68a82382018-10-02 13:16:55 -040027
28namespace sw
29{
30 struct Mipmap
31 {
32 const void *buffer[6];
33
34 float4 fWidth;
35 float4 fHeight;
36 float4 fDepth;
37
38 short uHalf[4];
39 short vHalf[4];
40 short wHalf[4];
41 short width[4];
42 short height[4];
43 short depth[4];
44 short onePitchP[4];
45 int4 pitchP;
46 int4 sliceP;
47 };
48
49 struct Texture
50 {
51 Mipmap mipmap[MIPMAP_LEVELS];
52
53 float LOD;
54 float4 widthHeightLOD;
55 float4 widthLOD;
56 float4 heightLOD;
57 float4 depthLOD;
58
59 word4 borderColor4[4];
60 float4 borderColorF[4];
61 float maxAnisotropy;
62 int baseLevel;
63 int maxLevel;
64 float minLod;
65 float maxLod;
66 };
67
68 enum SamplerType
69 {
70 SAMPLER_PIXEL,
71 SAMPLER_VERTEX
72 };
73
74 enum TextureType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
75 {
76 TEXTURE_NULL,
77 TEXTURE_2D,
78 TEXTURE_RECTANGLE,
79 TEXTURE_CUBE,
80 TEXTURE_3D,
81 TEXTURE_2D_ARRAY,
82
83 TEXTURE_LAST = TEXTURE_2D_ARRAY
84 };
85
86 enum FilterType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
87 {
88 FILTER_POINT,
89 FILTER_GATHER,
90 FILTER_MIN_POINT_MAG_LINEAR,
91 FILTER_MIN_LINEAR_MAG_POINT,
92 FILTER_LINEAR,
93 FILTER_ANISOTROPIC,
94
95 FILTER_LAST = FILTER_ANISOTROPIC
96 };
97
98 enum MipmapType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
99 {
100 MIPMAP_NONE,
101 MIPMAP_POINT,
102 MIPMAP_LINEAR,
103
104 MIPMAP_LAST = MIPMAP_LINEAR
105 };
106
107 enum AddressingMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT
108 {
109 ADDRESSING_WRAP,
110 ADDRESSING_CLAMP,
111 ADDRESSING_MIRROR,
112 ADDRESSING_MIRRORONCE,
113 ADDRESSING_BORDER, // Single color
114 ADDRESSING_SEAMLESS, // Border of pixels
115 ADDRESSING_LAYER,
116 ADDRESSING_TEXELFETCH,
117
118 ADDRESSING_LAST = ADDRESSING_TEXELFETCH
119 };
120
121 enum CompareFunc ENUM_UNDERLYING_TYPE_UNSIGNED_INT
122 {
123 COMPARE_BYPASS,
124 COMPARE_LESSEQUAL,
125 COMPARE_GREATEREQUAL,
126 COMPARE_LESS,
127 COMPARE_GREATER,
128 COMPARE_EQUAL,
129 COMPARE_NOTEQUAL,
130 COMPARE_ALWAYS,
131 COMPARE_NEVER,
132
133 COMPARE_LAST = COMPARE_NEVER
134 };
135
136 enum SwizzleType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
137 {
138 SWIZZLE_RED,
139 SWIZZLE_GREEN,
140 SWIZZLE_BLUE,
141 SWIZZLE_ALPHA,
142 SWIZZLE_ZERO,
143 SWIZZLE_ONE,
144
145 SWIZZLE_LAST = SWIZZLE_ONE
146 };
147
148 class Sampler
149 {
150 public:
151 struct State
152 {
153 State();
154
Ben Claytond66736a2019-02-19 17:06:30 +0000155 TextureType textureType;
Alexis Hetu696926d2019-03-18 11:30:01 -0400156 vk::Format textureFormat;
Ben Claytond66736a2019-02-19 17:06:30 +0000157 FilterType textureFilter;
158 AddressingMode addressingModeU;
159 AddressingMode addressingModeV;
160 AddressingMode addressingModeW;
161 MipmapType mipmapFilter;
162 bool sRGB;
163 SwizzleType swizzleR;
164 SwizzleType swizzleG;
165 SwizzleType swizzleB;
166 SwizzleType swizzleA;
167 bool highPrecisionFiltering;
168 CompareFunc compare;
Nicolas Capens68a82382018-10-02 13:16:55 -0400169
170 #if PERF_PROFILE
Ben Claytond66736a2019-02-19 17:06:30 +0000171 bool compressedFormat;
Nicolas Capens68a82382018-10-02 13:16:55 -0400172 #endif
173 };
174
175 Sampler();
176
177 ~Sampler();
178
179 State samplerState() const;
180
Alexis Hetu696926d2019-03-18 11:30:01 -0400181 void setTextureLevel(int face, int level, vk::Image *image, TextureType type);
Nicolas Capens68a82382018-10-02 13:16:55 -0400182
183 void setTextureFilter(FilterType textureFilter);
184 void setMipmapFilter(MipmapType mipmapFilter);
185 void setGatherEnable(bool enable);
186 void setAddressingModeU(AddressingMode addressingMode);
187 void setAddressingModeV(AddressingMode addressingMode);
188 void setAddressingModeW(AddressingMode addressingMode);
189 void setReadSRGB(bool sRGB);
190 void setBorderColor(const Color<float> &borderColor);
191 void setMaxAnisotropy(float maxAnisotropy);
192 void setHighPrecisionFiltering(bool highPrecisionFiltering);
193 void setSwizzleR(SwizzleType swizzleR);
194 void setSwizzleG(SwizzleType swizzleG);
195 void setSwizzleB(SwizzleType swizzleB);
196 void setSwizzleA(SwizzleType swizzleA);
197 void setCompareFunc(CompareFunc compare);
198 void setBaseLevel(int baseLevel);
199 void setMaxLevel(int maxLevel);
200 void setMinLod(float minLod);
201 void setMaxLod(float maxLod);
Nicolas Capens68a82382018-10-02 13:16:55 -0400202
203 static void setFilterQuality(FilterType maximumFilterQuality);
204 static void setMipmapQuality(MipmapType maximumFilterQuality);
205 void setMipmapLOD(float lod);
206
207 bool hasTexture() const;
208 bool hasUnsignedTexture() const;
209 bool hasCubeTexture() const;
210 bool hasVolumeTexture() const;
Nicolas Capens68a82382018-10-02 13:16:55 -0400211
212 const Texture &getTextureData();
213
214 private:
215 MipmapType mipmapFilter() const;
216 TextureType getTextureType() const;
217 FilterType getTextureFilter() const;
218 AddressingMode getAddressingModeU() const;
219 AddressingMode getAddressingModeV() const;
220 AddressingMode getAddressingModeW() const;
221 CompareFunc getCompareFunc() const;
222
Alexis Hetu696926d2019-03-18 11:30:01 -0400223 vk::Format textureFormat;
Nicolas Capens68a82382018-10-02 13:16:55 -0400224 TextureType textureType;
225
226 FilterType textureFilter;
227 AddressingMode addressingModeU;
228 AddressingMode addressingModeV;
229 AddressingMode addressingModeW;
230 MipmapType mipmapFilterState;
231 bool sRGB;
232 bool gather;
233 bool highPrecisionFiltering;
Nicolas Capens68a82382018-10-02 13:16:55 -0400234 int border;
235
236 SwizzleType swizzleR;
237 SwizzleType swizzleG;
238 SwizzleType swizzleB;
239 SwizzleType swizzleA;
240 CompareFunc compare;
241
242 Texture texture;
243 float exp2LOD;
244
245 static FilterType maximumTextureFilterQuality;
246 static MipmapType maximumMipmapFilterQuality;
247 };
248}
249
250#endif // sw_Sampler_hpp