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#ifndef VK_FORMAT_UTILS_HPP_
16#define VK_FORMAT_UTILS_HPP_
17
18#include <Vulkan/VulkanPlatform.h>
19
20namespace sw
21{
22 struct float4;
23}
24
25namespace vk
26{
27
28class Format
29{
30public:
31 Format() {}
32 Format(VkFormat format) : format(format) {}
33 inline operator VkFormat() const { return format; }
34
35 bool isUnsignedNormalized() const;
36 bool isSignedNormalized() const;
37 bool isSignedNonNormalizedInteger() const;
38 bool isUnsignedNonNormalizedInteger() const;
39 bool isNonNormalizedInteger() const;
40
41 VkImageAspectFlags getAspects() const;
42 Format getAspectFormat(VkImageAspectFlags aspect) const;
43 bool isStencil() const;
44 bool isDepth() const;
45 bool hasQuadLayout() const;
46 VkFormat getNonQuadLayoutFormat() const;
47 bool isSRGBformat() const;
48 bool isFloatFormat() const;
49 bool isYcbcrFormat() const;
50
51 bool isCompatible(const Format& other) const;
52 bool isCompressed() const;
53 VkFormat getDecompressedFormat() const;
54 int blockWidth() const;
55 int blockHeight() const;
56 int bytesPerBlock() const;
57
58 int componentCount() const;
59 bool isUnsignedComponent(int component) const;
60
61 int bytes() const;
62 int pitchB(int width, int border, bool target) const;
63 int sliceB(int width, int height, int border, bool target) const;
64
65 sw::float4 getScale() const;
66
67 // Texture sampling utilities
68 bool has16bitTextureFormat() const;
69 bool has8bitTextureComponents() const;
70 bool has16bitTextureComponents() const;
71 bool has32bitIntegerTextureComponents() const;
72 bool isRGBComponent(int component) const;
73
74private:
75 VkFormat compatibleFormat() const;
76 int sliceBUnpadded(int width, int height, int border, bool target) const;
77
78 VkFormat format = VK_FORMAT_UNDEFINED;
79};
80
81} // namespace vk
82
83#endif // VK_FORMAT_UTILS_HPP_