1 // 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
15 #include "VkSampler.hpp"
16
17 namespace vk {
18
SamplerState(const VkSamplerCreateInfo * pCreateInfo,const vk::SamplerYcbcrConversion * ycbcrConversion,VkSamplerFilteringPrecisionModeGOOGLE filteringPrecision)19 SamplerState::SamplerState(const VkSamplerCreateInfo *pCreateInfo, const vk::SamplerYcbcrConversion *ycbcrConversion, VkSamplerFilteringPrecisionModeGOOGLE filteringPrecision)
20 : Memset(this, 0)
21 , magFilter(pCreateInfo->magFilter)
22 , minFilter(pCreateInfo->minFilter)
23 , mipmapMode(pCreateInfo->mipmapMode)
24 , addressModeU(pCreateInfo->addressModeU)
25 , addressModeV(pCreateInfo->addressModeV)
26 , addressModeW(pCreateInfo->addressModeW)
27 , mipLodBias(pCreateInfo->mipLodBias)
28 , anisotropyEnable(pCreateInfo->anisotropyEnable)
29 , maxAnisotropy(pCreateInfo->maxAnisotropy)
30 , compareEnable(pCreateInfo->compareEnable)
31 , compareOp(pCreateInfo->compareOp)
32 , minLod(ClampLod(pCreateInfo->minLod))
33 , maxLod(ClampLod(pCreateInfo->maxLod))
34 , borderColor(pCreateInfo->borderColor)
35 , unnormalizedCoordinates(pCreateInfo->unnormalizedCoordinates)
36 , filteringPrecision(filteringPrecision)
37 {
38 if(ycbcrConversion)
39 {
40 ycbcrModel = ycbcrConversion->ycbcrModel;
41 studioSwing = (ycbcrConversion->ycbcrRange == VK_SAMPLER_YCBCR_RANGE_ITU_NARROW);
42 swappedChroma = (ycbcrConversion->components.r != VK_COMPONENT_SWIZZLE_R);
43 }
44 }
45
Sampler(const VkSamplerCreateInfo * pCreateInfo,void * mem,const SamplerState & samplerState,uint32_t samplerID)46 Sampler::Sampler(const VkSamplerCreateInfo *pCreateInfo, void *mem, const SamplerState &samplerState, uint32_t samplerID)
47 : SamplerState(samplerState)
48 , id(samplerID)
49 {
50 }
51
52 } // namespace vk
53