• 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 #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 isSRGBformat() const;
47 	bool isFloatFormat() const;
48 	bool isYcbcrFormat() const;
49 
50 	bool isCompatible(Format other) const;
51 	std::vector<Format> getCompatibleFormats() const;
52 
53 	bool isCompressed() const;
54 	VkFormat getDecompressedFormat() const;
55 	int blockWidth() const;
56 	int blockHeight() const;
57 	int bytesPerBlock() const;
58 
59 	int componentCount() const;
60 	bool isUnsignedComponent(int component) const;
61 
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;
65 
66 	sw::float4 getScale() const;
67 
68 	sw::int4 bitsPerComponent() const;
69 
70 	bool supportsColorAttachmentBlend() const;
71 
72 	// Texture sampling utilities
73 	bool has16bitPackedTextureFormat() const;
74 	bool has8bitTextureComponents() const;
75 	bool has16bitTextureComponents() const;
76 	bool has32bitIntegerTextureComponents() const;
77 	bool isRGBComponent(int component) const;
78 
79 	static uint8_t mapTo8bit(VkFormat format);
80 	static VkFormat mapFrom8bit(uint8_t format);
81 
82 private:
83 	VkFormat getCompatibilityClassRepresentative() const;
84 	size_t sliceBUnpadded(int width, int height, int border) const;
85 
86 	VkFormat format = VK_FORMAT_UNDEFINED;
87 };
88 
89 }  // namespace vk
90 
91 #endif  // VK_FORMAT_HPP_
92