blob: 3cff4a0e9726c11a48ba699155f44170b709d55e [file] [log] [blame]
Alexis Hetu6a1d92b2019-03-11 17:34:13 -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
Nicolas Capens67f052b2020-03-18 17:23:18 -040015#ifndef VK_FORMAT_HPP_
16#define VK_FORMAT_HPP_
Alexis Hetu6a1d92b2019-03-11 17:34:13 -040017
Nicolas Capensd37b0ab2019-12-13 09:35:16 -050018#include "System/Types.hpp"
Antonio Maiorano42fd1592020-04-27 11:30:40 -040019#include "Vulkan/VulkanPlatform.hpp"
Alexis Hetu25ec7b02019-03-12 14:19:22 -040020
Nicolas Capensa7e5b3e2022-03-27 01:51:17 -040021#include <vector>
22
Nicolas Capens157ba262019-12-10 17:49:14 -050023namespace vk {
Alexis Hetu6a1d92b2019-03-11 17:34:13 -040024
25class Format
26{
27public:
Alexis Hetu696926d2019-03-18 11:30:01 -040028 Format() {}
Nicolas Capens67f052b2020-03-18 17:23:18 -040029 Format(VkFormat format)
30 : format(format)
31 {}
Alexis Hetu25ec7b02019-03-12 14:19:22 -040032 inline operator VkFormat() const { return format; }
Alexis Hetu6a1d92b2019-03-11 17:34:13 -040033
Chris Forbes88289192019-08-28 16:49:36 -070034 bool isUnsignedNormalized() const;
35 bool isSignedNormalized() const;
Nicolas Capens9d9f30d2020-01-12 03:26:18 -050036 bool isSignedUnnormalizedInteger() const;
37 bool isUnsignedUnnormalizedInteger() const;
38 bool isUnnormalizedInteger() const;
Alexis Hetue733a262021-10-15 09:37:24 -040039 bool isUnsigned() const;
Alexis Hetu6a1d92b2019-03-11 17:34:13 -040040
Nicolas Capenscfe11c72019-05-16 09:58:26 -040041 VkImageAspectFlags getAspects() const;
42 Format getAspectFormat(VkImageAspectFlags aspect) const;
Alexis Hetue733a262021-10-15 09:37:24 -040043 VkFormat getClearFormat() const;
Alexis Hetu6a1d92b2019-03-11 17:34:13 -040044 bool isStencil() const;
45 bool isDepth() const;
Alexis Hetu25ec7b02019-03-12 14:19:22 -040046 bool isSRGBformat() const;
Alexis Hetu25ec7b02019-03-12 14:19:22 -040047 bool isFloatFormat() const;
Nicolas Capenscfe11c72019-05-16 09:58:26 -040048 bool isYcbcrFormat() const;
Alexis Hetu696926d2019-03-18 11:30:01 -040049
Nicolas Capensa7e5b3e2022-03-27 01:51:17 -040050 bool isCompatible(Format other) const;
51 std::vector<Format> getCompatibleFormats() const;
52
Alexis Hetu979f9402019-03-27 11:33:15 -040053 bool isCompressed() const;
Alexis Hetuac873342019-04-17 15:59:03 -040054 VkFormat getDecompressedFormat() const;
Alexis Hetu979f9402019-03-27 11:33:15 -040055 int blockWidth() const;
56 int blockHeight() const;
57 int bytesPerBlock() const;
58
Alexis Hetu696926d2019-03-18 11:30:01 -040059 int componentCount() const;
Alexis Hetu25ec7b02019-03-12 14:19:22 -040060 bool isUnsignedComponent(int component) const;
Alexis Hetu6a1d92b2019-03-11 17:34:13 -040061
Nicolas Capensf3692062021-11-23 00:40:22 -050062 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 Hetu25ec7b02019-03-12 14:19:22 -040065
Nicolas Capens88ac3672019-08-01 13:22:34 -040066 sw::float4 getScale() const;
Alexis Hetu696926d2019-03-18 11:30:01 -040067
Ari Suonpääa6ec85f2021-10-27 14:40:18 +030068 sw::int4 bitsPerComponent() const;
69
Nicolas Capensae100792020-06-11 13:48:40 -040070 bool supportsColorAttachmentBlend() const;
71
Alexis Hetu696926d2019-03-18 11:30:01 -040072 // Texture sampling utilities
Sean Risserc9625f12020-03-20 11:12:00 -040073 bool has16bitPackedTextureFormat() const;
Alexis Hetu696926d2019-03-18 11:30:01 -040074 bool has8bitTextureComponents() const;
75 bool has16bitTextureComponents() const;
76 bool has32bitIntegerTextureComponents() const;
Alexis Hetu696926d2019-03-18 11:30:01 -040077 bool isRGBComponent(int component) const;
78
Nicolas Capens67f052b2020-03-18 17:23:18 -040079 static uint8_t mapTo8bit(VkFormat format);
Alexis Hetu41a476e2021-02-16 17:38:55 -050080 static VkFormat mapFrom8bit(uint8_t format);
Nicolas Capens67f052b2020-03-18 17:23:18 -040081
Alexis Hetu6a1d92b2019-03-11 17:34:13 -040082private:
Nicolas Capensa7e5b3e2022-03-27 01:51:17 -040083 VkFormat getCompatibilityClassRepresentative() const;
Nicolas Capensf3692062021-11-23 00:40:22 -050084 size_t sliceBUnpadded(int width, int height, int border) const;
Alexis Hetu04dae5e2019-04-08 13:41:50 -040085
Alexis Hetu696926d2019-03-18 11:30:01 -040086 VkFormat format = VK_FORMAT_UNDEFINED;
Alexis Hetu6a1d92b2019-03-11 17:34:13 -040087};
88
Nicolas Capens157ba262019-12-10 17:49:14 -050089} // namespace vk
Alexis Hetu6a1d92b2019-03-11 17:34:13 -040090
Sean Risserc9625f12020-03-20 11:12:00 -040091#endif // VK_FORMAT_HPP_