blob: 6aedc3374c0bf7e540c6edede495ceb66feb4637 [file] [log] [blame]
Ben Clayton96fbe082019-04-16 19:28:11 -04001// Copyright 2019 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
Ben Clayton96fbe082019-04-16 19:28:11 -040015#include "SpirvShader.hpp"
16
Ben Claytonbc1c067be2019-12-17 20:37:37 +000017#include "SamplerCore.hpp" // TODO: Figure out what's needed.
18#include "Device/Config.hpp"
Ben Clayton25e06e02020-02-07 11:19:08 +000019#include "System/Debug.hpp"
Ben Clayton96fbe082019-04-16 19:28:11 -040020#include "System/Math.hpp"
Alexis Hetu6448bd62019-06-11 15:58:59 -040021#include "Vulkan/VkDescriptorSetLayout.hpp"
22#include "Vulkan/VkDevice.hpp"
Ben Clayton96fbe082019-04-16 19:28:11 -040023#include "Vulkan/VkImageView.hpp"
24#include "Vulkan/VkSampler.hpp"
Ben Clayton96fbe082019-04-16 19:28:11 -040025
26#include <spirv/unified1/spirv.hpp>
Ben Clayton96fbe082019-04-16 19:28:11 -040027
Alexis Hetu710fcd52019-05-24 17:20:21 -040028#include <climits>
Ben Clayton96fbe082019-04-16 19:28:11 -040029#include <mutex>
30
Ben Clayton96fbe082019-04-16 19:28:11 -040031namespace sw {
32
Alexis Hetue2601902021-05-07 13:59:00 -040033SpirvShader::ImageSampler *SpirvShader::getImageSampler(const vk::Device *device, uint32_t inst, uint32_t samplerId, uint32_t imageViewId)
Nicolas Capens125dba02019-04-24 02:03:22 -040034{
Nicolas Capensfa7d1362019-05-01 20:26:14 -040035 ImageInstruction instruction(inst);
Alexis Hetue2601902021-05-07 13:59:00 -040036 ASSERT(imageViewId != 0 && (samplerId != 0 || instruction.samplerMethod == Fetch));
37 ASSERT(device);
Nicolas Capensfa7d1362019-05-01 20:26:14 -040038
Alexis Hetue2601902021-05-07 13:59:00 -040039 vk::Device::SamplingRoutineCache::Key key = { inst, samplerId, imageViewId };
Ben Clayton96fbe082019-04-16 19:28:11 -040040
Alexis Hetue2601902021-05-07 13:59:00 -040041 auto createSamplingRoutine = [&device](const vk::Device::SamplingRoutineCache::Key &key) {
42 ImageInstruction instruction(key.instruction);
43 const vk::Identifier::State imageViewState = vk::Identifier(key.imageView).getState();
44 const vk::SamplerState *vkSamplerState = (key.sampler != 0) ? device->findSampler(key.sampler) : nullptr;
Alexis Hetu41a476e2021-02-16 17:38:55 -050045
46 auto type = imageViewState.imageViewType;
47 auto samplerMethod = static_cast<SamplerMethod>(instruction.samplerMethod);
Ben Clayton96fbe082019-04-16 19:28:11 -040048
Nicolas Capens1c294772020-03-28 23:04:55 -040049 Sampler samplerState = {};
50 samplerState.textureType = type;
Alexis Hetu41a476e2021-02-16 17:38:55 -050051 samplerState.textureFormat = imageViewState.format;
Chris Forbes45f9a932019-05-08 13:30:38 -070052
Alexis Hetue2601902021-05-07 13:59:00 -040053 samplerState.addressingModeU = convertAddressingMode(0, vkSamplerState, type);
54 samplerState.addressingModeV = convertAddressingMode(1, vkSamplerState, type);
55 samplerState.addressingModeW = convertAddressingMode(2, vkSamplerState, type);
Nicolas Capens51e9e562019-05-16 14:01:16 -040056
Alexis Hetue2601902021-05-07 13:59:00 -040057 samplerState.mipmapFilter = convertMipmapMode(vkSamplerState);
Alexis Hetu41a476e2021-02-16 17:38:55 -050058 samplerState.swizzle = imageViewState.mapping;
Nicolas Capens1c294772020-03-28 23:04:55 -040059 samplerState.gatherComponent = instruction.gatherComponent;
Nicolas Capensdbd02752019-08-20 10:59:58 -040060
Alexis Hetue2601902021-05-07 13:59:00 -040061 if(vkSamplerState)
Nicolas Capens1c294772020-03-28 23:04:55 -040062 {
Alexis Hetue2601902021-05-07 13:59:00 -040063 samplerState.textureFilter = convertFilterMode(vkSamplerState, type, samplerMethod);
64 samplerState.border = vkSamplerState->borderColor;
Nicolas Capensdbd02752019-08-20 10:59:58 -040065
Alexis Hetue2601902021-05-07 13:59:00 -040066 samplerState.mipmapFilter = convertMipmapMode(vkSamplerState);
67 samplerState.highPrecisionFiltering = (vkSamplerState->filteringPrecision == VK_SAMPLER_FILTERING_PRECISION_MODE_HIGH_GOOGLE);
Nicolas Capens7f469172020-03-17 17:29:11 -040068
Alexis Hetue2601902021-05-07 13:59:00 -040069 samplerState.compareEnable = (vkSamplerState->compareEnable != VK_FALSE);
70 samplerState.compareOp = vkSamplerState->compareOp;
71 samplerState.unnormalizedCoordinates = (vkSamplerState->unnormalizedCoordinates != VK_FALSE);
Nicolas Capense2535df2019-05-06 10:37:50 -040072
Alexis Hetue2601902021-05-07 13:59:00 -040073 samplerState.ycbcrModel = vkSamplerState->ycbcrModel;
74 samplerState.studioSwing = vkSamplerState->studioSwing;
75 samplerState.swappedChroma = vkSamplerState->swappedChroma;
Ben Clayton96fbe082019-04-16 19:28:11 -040076
Alexis Hetue2601902021-05-07 13:59:00 -040077 samplerState.mipLodBias = vkSamplerState->mipLodBias;
78 samplerState.maxAnisotropy = vkSamplerState->maxAnisotropy;
79 samplerState.minLod = vkSamplerState->minLod;
80 samplerState.maxLod = vkSamplerState->maxLod;
Alexis Hetuf239c9f2021-02-09 18:02:11 -050081
82 // If there's a single mip level and filtering doesn't depend on the LOD level,
83 // the sampler will need to compute the LOD to produce the proper result.
84 // Otherwise, it can be ignored.
85 // We can skip the LOD computation for all modes, except LOD query,
86 // where we have to return the proper value even if nothing else requires it.
87 if(imageViewState.singleMipLevel &&
88 (samplerState.textureFilter != FILTER_MIN_POINT_MAG_LINEAR) &&
89 (samplerState.textureFilter != FILTER_MIN_LINEAR_MAG_POINT) &&
90 (samplerMethod != Query))
91 {
92 samplerState.minLod = 0.0f;
93 samplerState.maxLod = 0.0f;
94 }
Nicolas Capens1c294772020-03-28 23:04:55 -040095 }
Nicolas Capens1c004412020-07-27 11:55:14 -040096 else
97 {
98 // OpImageFetch does not take a sampler descriptor, but for VK_EXT_image_robustness
99 // requires replacing invalid texels with zero.
Nicolas Capens1c004412020-07-27 11:55:14 -0400100 // TODO(b/162327166): Only perform bounds checks when VK_EXT_image_robustness is enabled.
101 samplerState.border = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
102 }
Nicolas Capens1c294772020-03-28 23:04:55 -0400103
104 return emitSamplerRoutine(instruction, samplerState);
105 };
106
Alexis Hetue2601902021-05-07 13:59:00 -0400107 vk::Device::SamplingRoutineCache *cache = device->getSamplingRoutineCache();
Nicolas Capens1c294772020-03-28 23:04:55 -0400108 auto routine = cache->getOrCreate(key, createSamplingRoutine);
109
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000110 return (ImageSampler *)(routine->getEntry());
Nicolas Capens97da7822019-04-30 17:33:26 -0400111}
Nicolas Capens125dba02019-04-24 02:03:22 -0400112
Ben Clayton6897e9b2019-07-16 17:27:27 +0100113std::shared_ptr<rr::Routine> SpirvShader::emitSamplerRoutine(ImageInstruction instruction, const Sampler &samplerState)
Nicolas Capens97da7822019-04-30 17:33:26 -0400114{
115 // TODO(b/129523279): Hold a separate mutex lock for the sampler being built.
Nicolas Capens6c11cf22020-03-19 15:21:13 -0400116 rr::Function<Void(Pointer<Byte>, Pointer<SIMD::Float>, Pointer<SIMD::Float>, Pointer<Byte>)> function;
Nicolas Capensa47a5162019-04-24 02:41:27 -0400117 {
Nicolas Capens97da7822019-04-30 17:33:26 -0400118 Pointer<Byte> texture = function.Arg<0>();
Nicolas Capens6c11cf22020-03-19 15:21:13 -0400119 Pointer<SIMD::Float> in = function.Arg<1>();
120 Pointer<SIMD::Float> out = function.Arg<2>();
121 Pointer<Byte> constants = function.Arg<3>();
Nicolas Capensa195abb2019-04-25 17:15:56 -0400122
Nicolas Capensfda74a62020-10-02 23:49:59 -0400123 SIMD::Float uvwa[4];
124 SIMD::Float dRef;
125 SIMD::Float lodOrBias; // Explicit level-of-detail, or bias added to the implicit level-of-detail (depending on samplerMethod).
126 Vector4f dsx;
127 Vector4f dsy;
128 Vector4i offset;
129 SIMD::Int sampleId;
Nicolas Capens97da7822019-04-30 17:33:26 -0400130 SamplerFunction samplerFunction = instruction.getSamplerFunction();
131
132 uint32_t i = 0;
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000133 for(; i < instruction.coordinates; i++)
Nicolas Capens420d9da2019-04-26 17:44:42 -0400134 {
Nicolas Capens2e40a572020-07-29 14:18:55 -0400135 uvwa[i] = in[i];
Nicolas Capens420d9da2019-04-26 17:44:42 -0400136 }
137
Nicolas Capens81bc9d92019-12-16 15:05:57 -0500138 if(instruction.isDref())
Chris Forbesc71c17f2019-05-04 10:01:04 -0700139 {
Nicolas Capens2e40a572020-07-29 14:18:55 -0400140 dRef = in[i];
Chris Forbesc71c17f2019-05-04 10:01:04 -0700141 i++;
142 }
143
Chris Forbesf7d78f72019-05-17 16:20:01 -0700144 if(instruction.samplerMethod == Lod || instruction.samplerMethod == Bias || instruction.samplerMethod == Fetch)
Nicolas Capens97da7822019-04-30 17:33:26 -0400145 {
146 lodOrBias = in[i];
147 i++;
148 }
149 else if(instruction.samplerMethod == Grad)
150 {
Nicolas Capens2a25ed82019-06-14 11:26:14 -0400151 for(uint32_t j = 0; j < instruction.grad; j++, i++)
Nicolas Capens97da7822019-04-30 17:33:26 -0400152 {
153 dsx[j] = in[i];
154 }
155
Nicolas Capens2a25ed82019-06-14 11:26:14 -0400156 for(uint32_t j = 0; j < instruction.grad; j++, i++)
Nicolas Capens97da7822019-04-30 17:33:26 -0400157 {
158 dsy[j] = in[i];
159 }
160 }
161
Nicolas Capens2a25ed82019-06-14 11:26:14 -0400162 for(uint32_t j = 0; j < instruction.offset; j++, i++)
Nicolas Capens97da7822019-04-30 17:33:26 -0400163 {
Nicolas Capens2e40a572020-07-29 14:18:55 -0400164 offset[j] = As<SIMD::Int>(in[i]);
Nicolas Capens97da7822019-04-30 17:33:26 -0400165 }
166
Alexis Hetu8a6dcf72019-11-26 17:24:42 -0500167 if(instruction.sample)
168 {
169 sampleId = As<SIMD::Int>(in[i]);
170 }
Nicolas Capens2a25ed82019-06-14 11:26:14 -0400171
Nicolas Capens977a0a42019-05-16 16:44:05 -0400172 SamplerCore s(constants, samplerState);
Nicolas Capens97da7822019-04-30 17:33:26 -0400173
Nicolas Capens8ac0bd62019-06-06 13:03:56 -0400174 // For explicit-lod instructions the LOD can be different per SIMD lane. SamplerCore currently assumes
175 // a single LOD per four elements, so we sample the image again for each LOD separately.
176 if(samplerFunction.method == Lod || samplerFunction.method == Grad) // TODO(b/133868964): Also handle divergent Bias and Fetch with Lod.
177 {
178 auto lod = Pointer<Float>(&lodOrBias);
179
180 For(Int i = 0, i < SIMD::Width, i++)
181 {
182 SIMD::Float dPdx;
183 SIMD::Float dPdy;
184
185 dPdx.x = Pointer<Float>(&dsx.x)[i];
186 dPdx.y = Pointer<Float>(&dsx.y)[i];
187 dPdx.z = Pointer<Float>(&dsx.z)[i];
188
189 dPdy.x = Pointer<Float>(&dsy.x)[i];
190 dPdy.y = Pointer<Float>(&dsy.y)[i];
191 dPdy.z = Pointer<Float>(&dsy.z)[i];
192
Nicolas Capens2e40a572020-07-29 14:18:55 -0400193 Vector4f sample = s.sampleTexture(texture, uvwa, dRef, lod[i], dPdx, dPdy, offset, sampleId, samplerFunction);
Nicolas Capens8ac0bd62019-06-06 13:03:56 -0400194
195 Pointer<Float> rgba = out;
196 rgba[0 * SIMD::Width + i] = Pointer<Float>(&sample.x)[i];
197 rgba[1 * SIMD::Width + i] = Pointer<Float>(&sample.y)[i];
198 rgba[2 * SIMD::Width + i] = Pointer<Float>(&sample.z)[i];
199 rgba[3 * SIMD::Width + i] = Pointer<Float>(&sample.w)[i];
200 }
201 }
202 else
203 {
Nicolas Capens2e40a572020-07-29 14:18:55 -0400204 Vector4f sample = s.sampleTexture(texture, uvwa, dRef, lodOrBias.x, (dsx.x), (dsy.x), offset, sampleId, samplerFunction);
Nicolas Capens8ac0bd62019-06-06 13:03:56 -0400205
206 Pointer<SIMD::Float> rgba = out;
207 rgba[0] = sample.x;
208 rgba[1] = sample.y;
209 rgba[2] = sample.z;
210 rgba[3] = sample.w;
211 }
Nicolas Capens022bd572019-04-29 23:45:25 -0400212 }
213
Alexis Hetu6448bd62019-06-11 15:58:59 -0400214 return function("sampler");
Nicolas Capens9e735102019-04-18 15:03:06 -0400215}
216
Alexis Hetue2601902021-05-07 13:59:00 -0400217sw::FilterType SpirvShader::convertFilterMode(const vk::SamplerState *samplerState, VkImageViewType imageViewType, SamplerMethod samplerMethod)
Nicolas Capens9e735102019-04-18 15:03:06 -0400218{
Alexis Hetu41a476e2021-02-16 17:38:55 -0500219 if(samplerMethod == Gather)
Nicolas Capens73c24e42020-08-05 09:50:20 -0400220 {
221 return FILTER_GATHER;
222 }
223
Alexis Hetu41a476e2021-02-16 17:38:55 -0500224 if(samplerMethod == Fetch)
Nicolas Capens73c24e42020-08-05 09:50:20 -0400225 {
226 return FILTER_POINT;
227 }
228
Alexis Hetue2601902021-05-07 13:59:00 -0400229 if(samplerState->anisotropyEnable != VK_FALSE)
Alexis Hetu21be09d2019-12-17 16:53:53 -0500230 {
Nicolas Capens73c24e42020-08-05 09:50:20 -0400231 if(imageViewType == VK_IMAGE_VIEW_TYPE_2D || imageViewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)
232 {
Alexis Hetu41a476e2021-02-16 17:38:55 -0500233 if(samplerMethod != Lod) // TODO(b/162926129): Support anisotropic filtering with explicit LOD.
Nicolas Capens73c24e42020-08-05 09:50:20 -0400234 {
235 return FILTER_ANISOTROPIC;
236 }
237 }
Alexis Hetu21be09d2019-12-17 16:53:53 -0500238 }
239
Alexis Hetue2601902021-05-07 13:59:00 -0400240 switch(samplerState->magFilter)
Nicolas Capens9e735102019-04-18 15:03:06 -0400241 {
Nicolas Capens112faf42019-12-13 17:32:26 -0500242 case VK_FILTER_NEAREST:
Alexis Hetue2601902021-05-07 13:59:00 -0400243 switch(samplerState->minFilter)
Nicolas Capens112faf42019-12-13 17:32:26 -0500244 {
245 case VK_FILTER_NEAREST: return FILTER_POINT;
246 case VK_FILTER_LINEAR: return FILTER_MIN_LINEAR_MAG_POINT;
Nicolas Capens9e735102019-04-18 15:03:06 -0400247 default:
Alexis Hetue2601902021-05-07 13:59:00 -0400248 UNSUPPORTED("minFilter %d", samplerState->minFilter);
Nicolas Capens112faf42019-12-13 17:32:26 -0500249 return FILTER_POINT;
250 }
251 break;
252 case VK_FILTER_LINEAR:
Alexis Hetue2601902021-05-07 13:59:00 -0400253 switch(samplerState->minFilter)
Nicolas Capens112faf42019-12-13 17:32:26 -0500254 {
255 case VK_FILTER_NEAREST: return FILTER_MIN_POINT_MAG_LINEAR;
256 case VK_FILTER_LINEAR: return FILTER_LINEAR;
257 default:
Alexis Hetue2601902021-05-07 13:59:00 -0400258 UNSUPPORTED("minFilter %d", samplerState->minFilter);
Nicolas Capens112faf42019-12-13 17:32:26 -0500259 return FILTER_POINT;
260 }
261 break;
262 default:
263 break;
Nicolas Capens9e735102019-04-18 15:03:06 -0400264 }
Ben Clayton8115f1e2019-06-11 16:13:56 +0100265
Alexis Hetue2601902021-05-07 13:59:00 -0400266 UNSUPPORTED("magFilter %d", samplerState->magFilter);
Ben Clayton8115f1e2019-06-11 16:13:56 +0100267 return FILTER_POINT;
Nicolas Capens9e735102019-04-18 15:03:06 -0400268}
269
Alexis Hetue2601902021-05-07 13:59:00 -0400270sw::MipmapType SpirvShader::convertMipmapMode(const vk::SamplerState *samplerState)
Nicolas Capens9e735102019-04-18 15:03:06 -0400271{
Alexis Hetue2601902021-05-07 13:59:00 -0400272 if(!samplerState)
Nicolas Capensdbd02752019-08-20 10:59:58 -0400273 {
274 return MIPMAP_POINT; // Samplerless operations (OpImageFetch) can take an integer Lod operand.
275 }
276
Alexis Hetue2601902021-05-07 13:59:00 -0400277 if(samplerState->ycbcrModel != VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY)
Nicolas Capens51e9e562019-05-16 14:01:16 -0400278 {
Nicolas Capens77b43d62020-03-12 00:20:00 -0400279 // TODO(b/151263485): Check image view level count instead.
280 return MIPMAP_NONE;
Nicolas Capens51e9e562019-05-16 14:01:16 -0400281 }
282
Alexis Hetue2601902021-05-07 13:59:00 -0400283 switch(samplerState->mipmapMode)
Nicolas Capens9e735102019-04-18 15:03:06 -0400284 {
Nicolas Capens112faf42019-12-13 17:32:26 -0500285 case VK_SAMPLER_MIPMAP_MODE_NEAREST: return MIPMAP_POINT;
286 case VK_SAMPLER_MIPMAP_MODE_LINEAR: return MIPMAP_LINEAR;
287 default:
Alexis Hetue2601902021-05-07 13:59:00 -0400288 UNSUPPORTED("mipmapMode %d", samplerState->mipmapMode);
Nicolas Capens112faf42019-12-13 17:32:26 -0500289 return MIPMAP_POINT;
Nicolas Capens9e735102019-04-18 15:03:06 -0400290 }
291}
292
Alexis Hetue2601902021-05-07 13:59:00 -0400293sw::AddressingMode SpirvShader::convertAddressingMode(int coordinateIndex, const vk::SamplerState *samplerState, VkImageViewType imageViewType)
Nicolas Capens9e735102019-04-18 15:03:06 -0400294{
Nicolas Capens6a12e092019-04-29 17:26:51 -0400295 switch(imageViewType)
296 {
Nicolas Capens112faf42019-12-13 17:32:26 -0500297 case VK_IMAGE_VIEW_TYPE_1D:
298 case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
299 if(coordinateIndex >= 1)
300 {
301 return ADDRESSING_UNUSED;
302 }
303 break;
304 case VK_IMAGE_VIEW_TYPE_2D:
305 case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
306 if(coordinateIndex == 2)
307 {
308 return ADDRESSING_UNUSED;
309 }
310 break;
Nicolas Capens30873702020-08-01 09:17:23 -0400311
Nicolas Capens112faf42019-12-13 17:32:26 -0500312 case VK_IMAGE_VIEW_TYPE_3D:
313 break;
Nicolas Capens30873702020-08-01 09:17:23 -0400314
Nicolas Capens112faf42019-12-13 17:32:26 -0500315 case VK_IMAGE_VIEW_TYPE_CUBE:
316 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
317 if(coordinateIndex <= 1) // Cube faces themselves are addressed as 2D images.
318 {
319 // Vulkan 1.1 spec:
320 // "Cube images ignore the wrap modes specified in the sampler. Instead, if VK_FILTER_NEAREST is used within a mip level then
321 // VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE is used, and if VK_FILTER_LINEAR is used within a mip level then sampling at the edges
322 // is performed as described earlier in the Cube map edge handling section."
323 // This corresponds with our 'SEAMLESS' addressing mode.
324 return ADDRESSING_SEAMLESS;
325 }
326 else // coordinateIndex == 2
327 {
328 // The cube face is an index into 2D array layers.
329 return ADDRESSING_CUBEFACE;
330 }
331 break;
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000332
Nicolas Capens112faf42019-12-13 17:32:26 -0500333 default:
334 UNSUPPORTED("imageViewType %d", imageViewType);
335 return ADDRESSING_WRAP;
Nicolas Capensa195abb2019-04-25 17:15:56 -0400336 }
337
Alexis Hetue2601902021-05-07 13:59:00 -0400338 if(!samplerState)
Nicolas Capensdbd02752019-08-20 10:59:58 -0400339 {
Nicolas Capens1c004412020-07-27 11:55:14 -0400340 // OpImageFetch does not take a sampler descriptor, but still needs a valid
341 // addressing mode that prevents out-of-bounds accesses:
Nicolas Capensdbd02752019-08-20 10:59:58 -0400342 // "The value returned by a read of an invalid texel is undefined, unless that
343 // read operation is from a buffer resource and the robustBufferAccess feature
344 // is enabled. In that case, an invalid texel is replaced as described by the
345 // robustBufferAccess feature." - Vulkan 1.1
346
Nicolas Capens1c004412020-07-27 11:55:14 -0400347 // VK_EXT_image_robustness requires nullifying out-of-bounds accesses.
348 // ADDRESSING_BORDER causes texel replacement to be performed.
Nicolas Capens1c004412020-07-27 11:55:14 -0400349 // TODO(b/162327166): Only perform bounds checks when VK_EXT_image_robustness is enabled.
350 return ADDRESSING_BORDER;
Nicolas Capensdbd02752019-08-20 10:59:58 -0400351 }
352
353 VkSamplerAddressMode addressMode = VK_SAMPLER_ADDRESS_MODE_REPEAT;
354 switch(coordinateIndex)
355 {
Alexis Hetue2601902021-05-07 13:59:00 -0400356 case 0: addressMode = samplerState->addressModeU; break;
357 case 1: addressMode = samplerState->addressModeV; break;
358 case 2: addressMode = samplerState->addressModeW; break;
Nicolas Capens112faf42019-12-13 17:32:26 -0500359 default: UNSUPPORTED("coordinateIndex: %d", coordinateIndex);
Nicolas Capensdbd02752019-08-20 10:59:58 -0400360 }
361
Nicolas Capens9e735102019-04-18 15:03:06 -0400362 switch(addressMode)
363 {
Nicolas Capens112faf42019-12-13 17:32:26 -0500364 case VK_SAMPLER_ADDRESS_MODE_REPEAT: return ADDRESSING_WRAP;
365 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT: return ADDRESSING_MIRROR;
366 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE: return ADDRESSING_CLAMP;
367 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER: return ADDRESSING_BORDER;
368 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE: return ADDRESSING_MIRRORONCE;
369 default:
370 UNSUPPORTED("addressMode %d", addressMode);
371 return ADDRESSING_WRAP;
Nicolas Capens9e735102019-04-18 15:03:06 -0400372 }
Ben Clayton96fbe082019-04-16 19:28:11 -0400373}
374
Ben Claytonbc1c067be2019-12-17 20:37:37 +0000375} // namespace sw