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 bool isUnsigned() const; 39 40 VkImageAspectFlags getAspects() const; 41 Format getAspectFormat(VkImageAspectFlags aspect) const; 42 VkFormat getClearFormat() const; 43 bool isStencil() const; 44 bool isDepth() const; 45 bool isSRGBformat() const; 46 bool isFloatFormat() const; 47 bool isYcbcrFormat() const; 48 49 bool isCompatible(const Format &other) const; 50 bool isCompressed() const; 51 VkFormat getDecompressedFormat() const; 52 int blockWidth() const; 53 int blockHeight() const; 54 int bytesPerBlock() const; 55 56 int componentCount() const; 57 bool isUnsignedComponent(int component) const; 58 59 size_t bytes() const; 60 size_t pitchB(int width, int border) const; 61 size_t sliceB(int width, int height, int border) const; 62 63 sw::float4 getScale() const; 64 65 sw::int4 bitsPerComponent() const; 66 67 bool supportsColorAttachmentBlend() const; 68 69 // Texture sampling utilities 70 bool has16bitPackedTextureFormat() const; 71 bool has8bitTextureComponents() const; 72 bool has16bitTextureComponents() const; 73 bool has32bitIntegerTextureComponents() const; 74 bool isRGBComponent(int component) const; 75 76 static uint8_t mapTo8bit(VkFormat format); 77 static VkFormat mapFrom8bit(uint8_t format); 78 79 private: 80 VkFormat compatibleFormat() const; 81 size_t sliceBUnpadded(int width, int height, int border) const; 82 83 VkFormat format = VK_FORMAT_UNDEFINED; 84 }; 85 86 } // namespace vk 87 88 #endif // VK_FORMAT_HPP_ 89