Alexis Hetu | 6a1d92b | 2019-03-11 17:34:13 -0400 | [diff] [blame] | 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 | |
Nicolas Capens | 67f052b | 2020-03-18 17:23:18 -0400 | [diff] [blame] | 15 | #ifndef VK_FORMAT_HPP_ |
| 16 | #define VK_FORMAT_HPP_ |
Alexis Hetu | 6a1d92b | 2019-03-11 17:34:13 -0400 | [diff] [blame] | 17 | |
Nicolas Capens | d37b0ab | 2019-12-13 09:35:16 -0500 | [diff] [blame] | 18 | #include "System/Types.hpp" |
Antonio Maiorano | 42fd159 | 2020-04-27 11:30:40 -0400 | [diff] [blame] | 19 | #include "Vulkan/VulkanPlatform.hpp" |
Alexis Hetu | 25ec7b0 | 2019-03-12 14:19:22 -0400 | [diff] [blame] | 20 | |
Nicolas Capens | a7e5b3e | 2022-03-27 01:51:17 -0400 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 23 | namespace vk { |
Alexis Hetu | 6a1d92b | 2019-03-11 17:34:13 -0400 | [diff] [blame] | 24 | |
| 25 | class Format |
| 26 | { |
| 27 | public: |
Alexis Hetu | 696926d | 2019-03-18 11:30:01 -0400 | [diff] [blame] | 28 | Format() {} |
Nicolas Capens | 67f052b | 2020-03-18 17:23:18 -0400 | [diff] [blame] | 29 | Format(VkFormat format) |
| 30 | : format(format) |
| 31 | {} |
Alexis Hetu | 25ec7b0 | 2019-03-12 14:19:22 -0400 | [diff] [blame] | 32 | inline operator VkFormat() const { return format; } |
Alexis Hetu | 6a1d92b | 2019-03-11 17:34:13 -0400 | [diff] [blame] | 33 | |
Chris Forbes | 8828919 | 2019-08-28 16:49:36 -0700 | [diff] [blame] | 34 | bool isUnsignedNormalized() const; |
| 35 | bool isSignedNormalized() const; |
Nicolas Capens | 9d9f30d | 2020-01-12 03:26:18 -0500 | [diff] [blame] | 36 | bool isSignedUnnormalizedInteger() const; |
| 37 | bool isUnsignedUnnormalizedInteger() const; |
| 38 | bool isUnnormalizedInteger() const; |
Alexis Hetu | e733a26 | 2021-10-15 09:37:24 -0400 | [diff] [blame] | 39 | bool isUnsigned() const; |
Alexis Hetu | 6a1d92b | 2019-03-11 17:34:13 -0400 | [diff] [blame] | 40 | |
Nicolas Capens | cfe11c7 | 2019-05-16 09:58:26 -0400 | [diff] [blame] | 41 | VkImageAspectFlags getAspects() const; |
| 42 | Format getAspectFormat(VkImageAspectFlags aspect) const; |
Alexis Hetu | e733a26 | 2021-10-15 09:37:24 -0400 | [diff] [blame] | 43 | VkFormat getClearFormat() const; |
Alexis Hetu | 6a1d92b | 2019-03-11 17:34:13 -0400 | [diff] [blame] | 44 | bool isStencil() const; |
| 45 | bool isDepth() const; |
Alexis Hetu | 25ec7b0 | 2019-03-12 14:19:22 -0400 | [diff] [blame] | 46 | bool isSRGBformat() const; |
Alexis Hetu | 25ec7b0 | 2019-03-12 14:19:22 -0400 | [diff] [blame] | 47 | bool isFloatFormat() const; |
Nicolas Capens | cfe11c7 | 2019-05-16 09:58:26 -0400 | [diff] [blame] | 48 | bool isYcbcrFormat() const; |
Alexis Hetu | 696926d | 2019-03-18 11:30:01 -0400 | [diff] [blame] | 49 | |
Nicolas Capens | a7e5b3e | 2022-03-27 01:51:17 -0400 | [diff] [blame] | 50 | bool isCompatible(Format other) const; |
| 51 | std::vector<Format> getCompatibleFormats() const; |
| 52 | |
Alexis Hetu | 979f940 | 2019-03-27 11:33:15 -0400 | [diff] [blame] | 53 | bool isCompressed() const; |
Alexis Hetu | ac87334 | 2019-04-17 15:59:03 -0400 | [diff] [blame] | 54 | VkFormat getDecompressedFormat() const; |
Alexis Hetu | 979f940 | 2019-03-27 11:33:15 -0400 | [diff] [blame] | 55 | int blockWidth() const; |
| 56 | int blockHeight() const; |
| 57 | int bytesPerBlock() const; |
| 58 | |
Alexis Hetu | 696926d | 2019-03-18 11:30:01 -0400 | [diff] [blame] | 59 | int componentCount() const; |
Alexis Hetu | 25ec7b0 | 2019-03-12 14:19:22 -0400 | [diff] [blame] | 60 | bool isUnsignedComponent(int component) const; |
Alexis Hetu | 6a1d92b | 2019-03-11 17:34:13 -0400 | [diff] [blame] | 61 | |
Nicolas Capens | f369206 | 2021-11-23 00:40:22 -0500 | [diff] [blame] | 62 | size_t bytes() const; |
| 63 | size_t pitchB(int width, int border) const; |
| 64 | size_t sliceB(int width, int height, int border) const; |
Alexis Hetu | 25ec7b0 | 2019-03-12 14:19:22 -0400 | [diff] [blame] | 65 | |
Nicolas Capens | 88ac367 | 2019-08-01 13:22:34 -0400 | [diff] [blame] | 66 | sw::float4 getScale() const; |
Alexis Hetu | 696926d | 2019-03-18 11:30:01 -0400 | [diff] [blame] | 67 | |
Ari Suonpää | a6ec85f | 2021-10-27 14:40:18 +0300 | [diff] [blame] | 68 | sw::int4 bitsPerComponent() const; |
| 69 | |
Nicolas Capens | ae10079 | 2020-06-11 13:48:40 -0400 | [diff] [blame] | 70 | bool supportsColorAttachmentBlend() const; |
| 71 | |
Alexis Hetu | 696926d | 2019-03-18 11:30:01 -0400 | [diff] [blame] | 72 | // Texture sampling utilities |
Sean Risser | c9625f1 | 2020-03-20 11:12:00 -0400 | [diff] [blame] | 73 | bool has16bitPackedTextureFormat() const; |
Alexis Hetu | 696926d | 2019-03-18 11:30:01 -0400 | [diff] [blame] | 74 | bool has8bitTextureComponents() const; |
| 75 | bool has16bitTextureComponents() const; |
| 76 | bool has32bitIntegerTextureComponents() const; |
Alexis Hetu | 696926d | 2019-03-18 11:30:01 -0400 | [diff] [blame] | 77 | bool isRGBComponent(int component) const; |
| 78 | |
Nicolas Capens | 67f052b | 2020-03-18 17:23:18 -0400 | [diff] [blame] | 79 | static uint8_t mapTo8bit(VkFormat format); |
Alexis Hetu | 41a476e | 2021-02-16 17:38:55 -0500 | [diff] [blame] | 80 | static VkFormat mapFrom8bit(uint8_t format); |
Nicolas Capens | 67f052b | 2020-03-18 17:23:18 -0400 | [diff] [blame] | 81 | |
Alexis Hetu | 6a1d92b | 2019-03-11 17:34:13 -0400 | [diff] [blame] | 82 | private: |
Nicolas Capens | a7e5b3e | 2022-03-27 01:51:17 -0400 | [diff] [blame] | 83 | VkFormat getCompatibilityClassRepresentative() const; |
Nicolas Capens | f369206 | 2021-11-23 00:40:22 -0500 | [diff] [blame] | 84 | size_t sliceBUnpadded(int width, int height, int border) const; |
Alexis Hetu | 04dae5e | 2019-04-08 13:41:50 -0400 | [diff] [blame] | 85 | |
Alexis Hetu | 696926d | 2019-03-18 11:30:01 -0400 | [diff] [blame] | 86 | VkFormat format = VK_FORMAT_UNDEFINED; |
Alexis Hetu | 6a1d92b | 2019-03-11 17:34:13 -0400 | [diff] [blame] | 87 | }; |
| 88 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 89 | } // namespace vk |
Alexis Hetu | 6a1d92b | 2019-03-11 17:34:13 -0400 | [diff] [blame] | 90 | |
Sean Risser | c9625f1 | 2020-03-20 11:12:00 -0400 | [diff] [blame] | 91 | #endif // VK_FORMAT_HPP_ |