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