1*03ce13f7SAndroid Build Coastguard Worker // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
2*03ce13f7SAndroid Build Coastguard Worker //
3*03ce13f7SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*03ce13f7SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*03ce13f7SAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*03ce13f7SAndroid Build Coastguard Worker //
7*03ce13f7SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0
8*03ce13f7SAndroid Build Coastguard Worker //
9*03ce13f7SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*03ce13f7SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*03ce13f7SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*03ce13f7SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*03ce13f7SAndroid Build Coastguard Worker // limitations under the License.
14*03ce13f7SAndroid Build Coastguard Worker
15*03ce13f7SAndroid Build Coastguard Worker #ifndef VK_SAMPLER_HPP_
16*03ce13f7SAndroid Build Coastguard Worker #define VK_SAMPLER_HPP_
17*03ce13f7SAndroid Build Coastguard Worker
18*03ce13f7SAndroid Build Coastguard Worker #include "VkImageView.hpp" // For ResolveIdentityMapping()
19*03ce13f7SAndroid Build Coastguard Worker #include "Device/Config.hpp"
20*03ce13f7SAndroid Build Coastguard Worker #include "Device/Memset.hpp"
21*03ce13f7SAndroid Build Coastguard Worker #include "System/Math.hpp"
22*03ce13f7SAndroid Build Coastguard Worker
23*03ce13f7SAndroid Build Coastguard Worker #include <atomic>
24*03ce13f7SAndroid Build Coastguard Worker
25*03ce13f7SAndroid Build Coastguard Worker namespace vk {
26*03ce13f7SAndroid Build Coastguard Worker
27*03ce13f7SAndroid Build Coastguard Worker struct SamplerState : sw::Memset<SamplerState>
28*03ce13f7SAndroid Build Coastguard Worker {
29*03ce13f7SAndroid Build Coastguard Worker SamplerState(const VkSamplerCreateInfo *pCreateInfo, const vk::SamplerYcbcrConversion *ycbcrConversion,
30*03ce13f7SAndroid Build Coastguard Worker const VkClearColorValue &customBorderColor);
31*03ce13f7SAndroid Build Coastguard Worker
32*03ce13f7SAndroid Build Coastguard Worker // Prevents accessing mipmap levels out of range.
ClampLodvk::SamplerState33*03ce13f7SAndroid Build Coastguard Worker static float ClampLod(float lod)
34*03ce13f7SAndroid Build Coastguard Worker {
35*03ce13f7SAndroid Build Coastguard Worker return sw::clamp(lod, 0.0f, (float)(sw::MAX_TEXTURE_LOD));
36*03ce13f7SAndroid Build Coastguard Worker }
37*03ce13f7SAndroid Build Coastguard Worker
38*03ce13f7SAndroid Build Coastguard Worker const VkFilter magFilter = VK_FILTER_NEAREST;
39*03ce13f7SAndroid Build Coastguard Worker const VkFilter minFilter = VK_FILTER_NEAREST;
40*03ce13f7SAndroid Build Coastguard Worker const VkSamplerMipmapMode mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
41*03ce13f7SAndroid Build Coastguard Worker const VkSamplerAddressMode addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
42*03ce13f7SAndroid Build Coastguard Worker const VkSamplerAddressMode addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
43*03ce13f7SAndroid Build Coastguard Worker const VkSamplerAddressMode addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
44*03ce13f7SAndroid Build Coastguard Worker const float mipLodBias = 0.0f;
45*03ce13f7SAndroid Build Coastguard Worker const VkBool32 anisotropyEnable = VK_FALSE;
46*03ce13f7SAndroid Build Coastguard Worker const float maxAnisotropy = 0.0f;
47*03ce13f7SAndroid Build Coastguard Worker const VkBool32 compareEnable = VK_FALSE;
48*03ce13f7SAndroid Build Coastguard Worker const VkCompareOp compareOp = VK_COMPARE_OP_NEVER;
49*03ce13f7SAndroid Build Coastguard Worker const float minLod = 0.0f;
50*03ce13f7SAndroid Build Coastguard Worker const float maxLod = 0.0f;
51*03ce13f7SAndroid Build Coastguard Worker const VkBorderColor borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
52*03ce13f7SAndroid Build Coastguard Worker const VkClearColorValue customBorderColor = {};
53*03ce13f7SAndroid Build Coastguard Worker const VkBool32 unnormalizedCoordinates = VK_FALSE;
54*03ce13f7SAndroid Build Coastguard Worker
55*03ce13f7SAndroid Build Coastguard Worker VkSamplerYcbcrModelConversion ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
56*03ce13f7SAndroid Build Coastguard Worker const bool highPrecisionFiltering = false;
57*03ce13f7SAndroid Build Coastguard Worker bool studioSwing = false; // Narrow range
58*03ce13f7SAndroid Build Coastguard Worker bool swappedChroma = false; // Cb/Cr components in reverse order
59*03ce13f7SAndroid Build Coastguard Worker VkFilter chromaFilter = VK_FILTER_NEAREST;
60*03ce13f7SAndroid Build Coastguard Worker VkChromaLocation chromaXOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
61*03ce13f7SAndroid Build Coastguard Worker VkChromaLocation chromaYOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
62*03ce13f7SAndroid Build Coastguard Worker };
63*03ce13f7SAndroid Build Coastguard Worker
64*03ce13f7SAndroid Build Coastguard Worker class Sampler : public Object<Sampler, VkSampler>, public SamplerState
65*03ce13f7SAndroid Build Coastguard Worker {
66*03ce13f7SAndroid Build Coastguard Worker public:
67*03ce13f7SAndroid Build Coastguard Worker Sampler(const VkSamplerCreateInfo *pCreateInfo, void *mem, const SamplerState &samplerState, uint32_t samplerID);
68*03ce13f7SAndroid Build Coastguard Worker
ComputeRequiredAllocationSize(const VkSamplerCreateInfo * pCreateInfo)69*03ce13f7SAndroid Build Coastguard Worker static size_t ComputeRequiredAllocationSize(const VkSamplerCreateInfo *pCreateInfo)
70*03ce13f7SAndroid Build Coastguard Worker {
71*03ce13f7SAndroid Build Coastguard Worker return 0;
72*03ce13f7SAndroid Build Coastguard Worker }
73*03ce13f7SAndroid Build Coastguard Worker
74*03ce13f7SAndroid Build Coastguard Worker const uint32_t id = 0;
75*03ce13f7SAndroid Build Coastguard Worker };
76*03ce13f7SAndroid Build Coastguard Worker
77*03ce13f7SAndroid Build Coastguard Worker class SamplerYcbcrConversion : public Object<SamplerYcbcrConversion, VkSamplerYcbcrConversion>
78*03ce13f7SAndroid Build Coastguard Worker {
79*03ce13f7SAndroid Build Coastguard Worker public:
SamplerYcbcrConversion(const VkSamplerYcbcrConversionCreateInfo * pCreateInfo,void * mem)80*03ce13f7SAndroid Build Coastguard Worker SamplerYcbcrConversion(const VkSamplerYcbcrConversionCreateInfo *pCreateInfo, void *mem)
81*03ce13f7SAndroid Build Coastguard Worker : format(pCreateInfo->format)
82*03ce13f7SAndroid Build Coastguard Worker , ycbcrModel(pCreateInfo->ycbcrModel)
83*03ce13f7SAndroid Build Coastguard Worker , ycbcrRange(pCreateInfo->ycbcrRange)
84*03ce13f7SAndroid Build Coastguard Worker , components(ResolveIdentityMapping(pCreateInfo->components))
85*03ce13f7SAndroid Build Coastguard Worker , xChromaOffset(pCreateInfo->xChromaOffset)
86*03ce13f7SAndroid Build Coastguard Worker , yChromaOffset(pCreateInfo->yChromaOffset)
87*03ce13f7SAndroid Build Coastguard Worker , chromaFilter(pCreateInfo->chromaFilter)
88*03ce13f7SAndroid Build Coastguard Worker , forceExplicitReconstruction(pCreateInfo->forceExplicitReconstruction)
89*03ce13f7SAndroid Build Coastguard Worker {
90*03ce13f7SAndroid Build Coastguard Worker }
91*03ce13f7SAndroid Build Coastguard Worker
92*03ce13f7SAndroid Build Coastguard Worker ~SamplerYcbcrConversion() = default;
93*03ce13f7SAndroid Build Coastguard Worker
ComputeRequiredAllocationSize(const VkSamplerYcbcrConversionCreateInfo * pCreateInfo)94*03ce13f7SAndroid Build Coastguard Worker static size_t ComputeRequiredAllocationSize(const VkSamplerYcbcrConversionCreateInfo *pCreateInfo)
95*03ce13f7SAndroid Build Coastguard Worker {
96*03ce13f7SAndroid Build Coastguard Worker return 0;
97*03ce13f7SAndroid Build Coastguard Worker }
98*03ce13f7SAndroid Build Coastguard Worker
99*03ce13f7SAndroid Build Coastguard Worker const VkFormat format = VK_FORMAT_UNDEFINED;
100*03ce13f7SAndroid Build Coastguard Worker const VkSamplerYcbcrModelConversion ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
101*03ce13f7SAndroid Build Coastguard Worker const VkSamplerYcbcrRange ycbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
102*03ce13f7SAndroid Build Coastguard Worker const VkComponentMapping components = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
103*03ce13f7SAndroid Build Coastguard Worker const VkChromaLocation xChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
104*03ce13f7SAndroid Build Coastguard Worker const VkChromaLocation yChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN;
105*03ce13f7SAndroid Build Coastguard Worker const VkFilter chromaFilter = VK_FILTER_NEAREST;
106*03ce13f7SAndroid Build Coastguard Worker const VkBool32 forceExplicitReconstruction = VK_FALSE;
107*03ce13f7SAndroid Build Coastguard Worker };
108*03ce13f7SAndroid Build Coastguard Worker
Cast(VkSampler object)109*03ce13f7SAndroid Build Coastguard Worker static inline Sampler *Cast(VkSampler object)
110*03ce13f7SAndroid Build Coastguard Worker {
111*03ce13f7SAndroid Build Coastguard Worker return Sampler::Cast(object);
112*03ce13f7SAndroid Build Coastguard Worker }
113*03ce13f7SAndroid Build Coastguard Worker
Cast(VkSamplerYcbcrConversion object)114*03ce13f7SAndroid Build Coastguard Worker static inline SamplerYcbcrConversion *Cast(VkSamplerYcbcrConversion object)
115*03ce13f7SAndroid Build Coastguard Worker {
116*03ce13f7SAndroid Build Coastguard Worker return SamplerYcbcrConversion::Cast(object);
117*03ce13f7SAndroid Build Coastguard Worker }
118*03ce13f7SAndroid Build Coastguard Worker
119*03ce13f7SAndroid Build Coastguard Worker } // namespace vk
120*03ce13f7SAndroid Build Coastguard Worker
121*03ce13f7SAndroid Build Coastguard Worker #endif // VK_SAMPLER_HPP_
122