xref: /aosp_15_r20/external/swiftshader/src/Vulkan/VkFormat.hpp (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
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_HPP_
16 #define VK_FORMAT_HPP_
17 
18 #include "System/Types.hpp"
19 #include "Vulkan/VulkanPlatform.hpp"
20 
21 #include <vector>
22 
23 namespace vk {
24 
25 class Format
26 {
27 public:
Format()28 	Format() {}
Format(VkFormat format)29 	Format(VkFormat format)
30 	    : format(format)
31 	{}
operator VkFormat() const32 	inline operator VkFormat() const { return format; }
33 
34 	bool isUnsignedNormalized() const;
35 	bool isSignedNormalized() const;
36 	bool isSignedUnnormalizedInteger() const;
37 	bool isUnsignedUnnormalizedInteger() const;
38 	bool isUnnormalizedInteger() const;
39 	bool isUnsigned() const;
40 
41 	VkImageAspectFlags getAspects() const;
42 	Format getAspectFormat(VkImageAspectFlags aspect) const;
43 	VkFormat getClearFormat() const;
44 	bool isStencil() const;
45 	bool isDepth() const;
46 	bool isBGRformat() const;
47 	bool isSRGBformat() const;
48 	bool isFloatFormat() const;
49 	bool isYcbcrFormat() const;
50 
51 	bool isCompatible(Format other) const;
52 	std::vector<Format> getCompatibleFormats() const;
53 
54 	bool isCompressed() const;
55 	VkFormat getDecompressedFormat() const;
56 	int blockWidth() const;
57 	int blockHeight() const;
58 	int bytesPerBlock() const;
59 
60 	int componentCount() const;
61 	bool isUnsignedComponent(int component) const;
62 
63 	size_t bytes() const;
64 	size_t pitchB(int width, int border) const;
65 	size_t sliceB(int width, int height, int border) const;
66 
67 	sw::float4 getScale() const;
68 
69 	sw::int4 bitsPerComponent() const;
70 
71 	bool supportsColorAttachmentBlend() const;
72 
73 	// Texture sampling utilities
74 	bool has16bitPackedTextureFormat() const;
75 	bool has8bitTextureComponents() const;
76 	bool has16bitTextureComponents() const;
77 	bool has32bitIntegerTextureComponents() const;
78 	bool isRGBComponent(int component) const;
79 
80 	static uint8_t mapTo8bit(VkFormat format);
81 	static VkFormat mapFrom8bit(uint8_t format);
82 
83 private:
84 	VkFormat getCompatibilityClassRepresentative() const;
85 	size_t sliceBUnpadded(int width, int height, int border) const;
86 
87 	VkFormat format = VK_FORMAT_UNDEFINED;
88 };
89 
90 }  // namespace vk
91 
92 #endif  // VK_FORMAT_HPP_
93