• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include "Vulkan/VulkanPlatform.hpp"
21 
22 namespace vk {
23 
24 class Format
25 {
26 public:
Format()27 	Format() {}
Format(VkFormat format)28 	Format(VkFormat format)
29 	    : format(format)
30 	{}
operator VkFormat() const31 	inline operator VkFormat() const { return format; }
32 
33 	bool isUnsignedNormalized() const;
34 	bool isSignedNormalized() const;
35 	bool isSignedUnnormalizedInteger() const;
36 	bool isUnsignedUnnormalizedInteger() const;
37 	bool isUnnormalizedInteger() const;
38 
39 	VkImageAspectFlags getAspects() const;
40 	Format getAspectFormat(VkImageAspectFlags aspect) const;
41 	bool isStencil() const;
42 	bool isDepth() const;
43 	bool isSRGBformat() const;
44 	bool isFloatFormat() const;
45 	bool isYcbcrFormat() const;
46 
47 	bool isCompatible(const Format &other) const;
48 	bool isCompressed() const;
49 	VkFormat getDecompressedFormat() const;
50 	int blockWidth() const;
51 	int blockHeight() const;
52 	int bytesPerBlock() const;
53 
54 	int componentCount() const;
55 	bool isUnsignedComponent(int component) const;
56 
57 	int bytes() const;
58 	int pitchB(int width, int border, bool target) const;
59 	int sliceB(int width, int height, int border, bool target) const;
60 
61 	sw::float4 getScale() const;
62 
63 	bool supportsColorAttachmentBlend() const;
64 
65 	// Texture sampling utilities
66 	bool has16bitPackedTextureFormat() const;
67 	bool has8bitTextureComponents() const;
68 	bool has16bitTextureComponents() const;
69 	bool has32bitIntegerTextureComponents() const;
70 	bool isRGBComponent(int component) const;
71 
72 	static uint8_t mapTo8bit(VkFormat format);
73 
74 private:
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_HPP_
84