Alexis Hetu | 5174c57 | 2018-11-19 11:30:43 -0500 | [diff] [blame] | 1 | // Copyright 2018 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 VK_SAMPLER_HPP_ |
| 16 | #define VK_SAMPLER_HPP_ |
| 17 | |
Nicolas Capens | 6b63c80 | 2019-05-16 11:10:34 -0400 | [diff] [blame] | 18 | #include "VkImageView.hpp" // For ResolveIdentityMapping() |
Nicolas Capens | 97da782 | 2019-04-30 17:33:26 -0400 | [diff] [blame] | 19 | #include "Device/Config.hpp" |
Nicolas Capens | f948cd1 | 2020-03-23 13:00:43 -0400 | [diff] [blame] | 20 | #include "Device/Memset.hpp" |
Nicolas Capens | 97da782 | 2019-04-30 17:33:26 -0400 | [diff] [blame] | 21 | #include "System/Math.hpp" |
Alexis Hetu | 5174c57 | 2018-11-19 11:30:43 -0500 | [diff] [blame] | 22 | |
Ben Clayton | eac32c4 | 2019-04-26 11:25:57 +0100 | [diff] [blame] | 23 | #include <atomic> |
| 24 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 25 | namespace vk { |
Alexis Hetu | 5174c57 | 2018-11-19 11:30:43 -0500 | [diff] [blame] | 26 | |
Nicolas Capens | f948cd1 | 2020-03-23 13:00:43 -0400 | [diff] [blame] | 27 | struct SamplerState : sw::Memset<SamplerState> |
Alexis Hetu | 5174c57 | 2018-11-19 11:30:43 -0500 | [diff] [blame] | 28 | { |
Antonio Maiorano | d9ba4b7 | 2020-05-04 14:38:59 -0400 | [diff] [blame] | 29 | SamplerState(const VkSamplerCreateInfo *pCreateInfo, const vk::SamplerYcbcrConversion *ycbcrConversion, VkSamplerFilteringPrecisionModeGOOGLE filteringPrecision); |
Alexis Hetu | 5174c57 | 2018-11-19 11:30:43 -0500 | [diff] [blame] | 30 | |
Nicolas Capens | 97da782 | 2019-04-30 17:33:26 -0400 | [diff] [blame] | 31 | // Prevents accessing mipmap levels out of range. |
| 32 | static float ClampLod(float lod) |
| 33 | { |
| 34 | return sw::clamp(lod, 0.0f, (float)(sw::MAX_TEXTURE_LOD)); |
| 35 | } |
| 36 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 37 | const VkFilter magFilter = VK_FILTER_NEAREST; |
| 38 | const VkFilter minFilter = VK_FILTER_NEAREST; |
| 39 | const VkSamplerMipmapMode mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
Nicolas Capens | 7d86727 | 2019-04-08 22:51:08 -0400 | [diff] [blame] | 40 | const VkSamplerAddressMode addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; |
| 41 | const VkSamplerAddressMode addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; |
| 42 | const VkSamplerAddressMode addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 43 | const float mipLodBias = 0.0f; |
| 44 | const VkBool32 anisotropyEnable = VK_FALSE; |
| 45 | const float maxAnisotropy = 0.0f; |
| 46 | const VkBool32 compareEnable = VK_FALSE; |
| 47 | const VkCompareOp compareOp = VK_COMPARE_OP_NEVER; |
| 48 | const float minLod = 0.0f; |
| 49 | const float maxLod = 0.0f; |
| 50 | const VkBorderColor borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; |
| 51 | const VkBool32 unnormalizedCoordinates = VK_FALSE; |
Ben Clayton | eac32c4 | 2019-04-26 11:25:57 +0100 | [diff] [blame] | 52 | |
Nicolas Capens | f948cd1 | 2020-03-23 13:00:43 -0400 | [diff] [blame] | 53 | VkSamplerYcbcrModelConversion ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY; |
Antonio Maiorano | d9ba4b7 | 2020-05-04 14:38:59 -0400 | [diff] [blame] | 54 | const VkSamplerFilteringPrecisionModeGOOGLE filteringPrecision = VK_SAMPLER_FILTERING_PRECISION_MODE_LOW_GOOGLE; |
Nicolas Capens | f948cd1 | 2020-03-23 13:00:43 -0400 | [diff] [blame] | 55 | bool studioSwing = false; // Narrow range |
| 56 | bool swappedChroma = false; // Cb/Cr components in reverse order |
| 57 | }; |
| 58 | |
| 59 | class Sampler : public Object<Sampler, VkSampler>, public SamplerState |
| 60 | { |
| 61 | public: |
Nicolas Capens | 73c4a0c | 2020-03-17 17:29:11 -0400 | [diff] [blame] | 62 | Sampler(const VkSamplerCreateInfo *pCreateInfo, void *mem, const SamplerState &samplerState, uint32_t samplerID); |
Nicolas Capens | f948cd1 | 2020-03-23 13:00:43 -0400 | [diff] [blame] | 63 | |
| 64 | static size_t ComputeRequiredAllocationSize(const VkSamplerCreateInfo *pCreateInfo) |
| 65 | { |
| 66 | return 0; |
| 67 | } |
| 68 | |
Nicolas Capens | 73c4a0c | 2020-03-17 17:29:11 -0400 | [diff] [blame] | 69 | const uint32_t id = 0; |
Alexis Hetu | 5174c57 | 2018-11-19 11:30:43 -0500 | [diff] [blame] | 70 | }; |
| 71 | |
Nicolas Capens | 6b63c80 | 2019-05-16 11:10:34 -0400 | [diff] [blame] | 72 | class SamplerYcbcrConversion : public Object<SamplerYcbcrConversion, VkSamplerYcbcrConversion> |
| 73 | { |
| 74 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 75 | SamplerYcbcrConversion(const VkSamplerYcbcrConversionCreateInfo *pCreateInfo, void *mem) |
| 76 | : format(pCreateInfo->format) |
| 77 | , ycbcrModel(pCreateInfo->ycbcrModel) |
| 78 | , ycbcrRange(pCreateInfo->ycbcrRange) |
| 79 | , components(ResolveIdentityMapping(pCreateInfo->components)) |
| 80 | , xChromaOffset(pCreateInfo->xChromaOffset) |
| 81 | , yChromaOffset(pCreateInfo->yChromaOffset) |
| 82 | , chromaFilter(pCreateInfo->chromaFilter) |
| 83 | , forceExplicitReconstruction(pCreateInfo->forceExplicitReconstruction) |
Nicolas Capens | 6b63c80 | 2019-05-16 11:10:34 -0400 | [diff] [blame] | 84 | { |
| 85 | } |
| 86 | |
| 87 | ~SamplerYcbcrConversion() = default; |
| 88 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 89 | static size_t ComputeRequiredAllocationSize(const VkSamplerYcbcrConversionCreateInfo *pCreateInfo) |
Nicolas Capens | 6b63c80 | 2019-05-16 11:10:34 -0400 | [diff] [blame] | 90 | { |
| 91 | return 0; |
| 92 | } |
| 93 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 94 | const VkFormat format = VK_FORMAT_UNDEFINED; |
Nicolas Capens | 6b63c80 | 2019-05-16 11:10:34 -0400 | [diff] [blame] | 95 | const VkSamplerYcbcrModelConversion ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 96 | const VkSamplerYcbcrRange ycbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL; |
| 97 | const VkComponentMapping components = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A }; |
| 98 | const VkChromaLocation xChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN; |
| 99 | const VkChromaLocation yChromaOffset = VK_CHROMA_LOCATION_COSITED_EVEN; |
| 100 | const VkFilter chromaFilter = VK_FILTER_NEAREST; |
| 101 | const VkBool32 forceExplicitReconstruction = VK_FALSE; |
Nicolas Capens | 6b63c80 | 2019-05-16 11:10:34 -0400 | [diff] [blame] | 102 | }; |
| 103 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 104 | static inline Sampler *Cast(VkSampler object) |
Alexis Hetu | 5174c57 | 2018-11-19 11:30:43 -0500 | [diff] [blame] | 105 | { |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 106 | return Sampler::Cast(object); |
Alexis Hetu | 5174c57 | 2018-11-19 11:30:43 -0500 | [diff] [blame] | 107 | } |
| 108 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 109 | static inline SamplerYcbcrConversion *Cast(VkSamplerYcbcrConversion object) |
Nicolas Capens | 6b63c80 | 2019-05-16 11:10:34 -0400 | [diff] [blame] | 110 | { |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 111 | return SamplerYcbcrConversion::Cast(object); |
Nicolas Capens | 6b63c80 | 2019-05-16 11:10:34 -0400 | [diff] [blame] | 112 | } |
| 113 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 114 | } // namespace vk |
Alexis Hetu | 5174c57 | 2018-11-19 11:30:43 -0500 | [diff] [blame] | 115 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 116 | #endif // VK_SAMPLER_HPP_ |