1*03ce13f7SAndroid Build Coastguard Worker // Copyright 2019 The SwiftShader Authors. All Rights Reserved. 2*03ce13f7SAndroid Build Coastguard Worker // 3*03ce13f7SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*03ce13f7SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*03ce13f7SAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*03ce13f7SAndroid Build Coastguard Worker // 7*03ce13f7SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 8*03ce13f7SAndroid Build Coastguard Worker // 9*03ce13f7SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*03ce13f7SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*03ce13f7SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*03ce13f7SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*03ce13f7SAndroid Build Coastguard Worker // limitations under the License. 14*03ce13f7SAndroid Build Coastguard Worker 15*03ce13f7SAndroid Build Coastguard Worker #ifndef VK_FORMAT_HPP_ 16*03ce13f7SAndroid Build Coastguard Worker #define VK_FORMAT_HPP_ 17*03ce13f7SAndroid Build Coastguard Worker 18*03ce13f7SAndroid Build Coastguard Worker #include "System/Types.hpp" 19*03ce13f7SAndroid Build Coastguard Worker #include "Vulkan/VulkanPlatform.hpp" 20*03ce13f7SAndroid Build Coastguard Worker 21*03ce13f7SAndroid Build Coastguard Worker #include <vector> 22*03ce13f7SAndroid Build Coastguard Worker 23*03ce13f7SAndroid Build Coastguard Worker namespace vk { 24*03ce13f7SAndroid Build Coastguard Worker 25*03ce13f7SAndroid Build Coastguard Worker class Format 26*03ce13f7SAndroid Build Coastguard Worker { 27*03ce13f7SAndroid Build Coastguard Worker public: Format()28*03ce13f7SAndroid Build Coastguard Worker Format() {} Format(VkFormat format)29*03ce13f7SAndroid Build Coastguard Worker Format(VkFormat format) 30*03ce13f7SAndroid Build Coastguard Worker : format(format) 31*03ce13f7SAndroid Build Coastguard Worker {} operator VkFormat() const32*03ce13f7SAndroid Build Coastguard Worker inline operator VkFormat() const { return format; } 33*03ce13f7SAndroid Build Coastguard Worker 34*03ce13f7SAndroid Build Coastguard Worker bool isUnsignedNormalized() const; 35*03ce13f7SAndroid Build Coastguard Worker bool isSignedNormalized() const; 36*03ce13f7SAndroid Build Coastguard Worker bool isSignedUnnormalizedInteger() const; 37*03ce13f7SAndroid Build Coastguard Worker bool isUnsignedUnnormalizedInteger() const; 38*03ce13f7SAndroid Build Coastguard Worker bool isUnnormalizedInteger() const; 39*03ce13f7SAndroid Build Coastguard Worker bool isUnsigned() const; 40*03ce13f7SAndroid Build Coastguard Worker 41*03ce13f7SAndroid Build Coastguard Worker VkImageAspectFlags getAspects() const; 42*03ce13f7SAndroid Build Coastguard Worker Format getAspectFormat(VkImageAspectFlags aspect) const; 43*03ce13f7SAndroid Build Coastguard Worker VkFormat getClearFormat() const; 44*03ce13f7SAndroid Build Coastguard Worker bool isStencil() const; 45*03ce13f7SAndroid Build Coastguard Worker bool isDepth() const; 46*03ce13f7SAndroid Build Coastguard Worker bool isBGRformat() const; 47*03ce13f7SAndroid Build Coastguard Worker bool isSRGBformat() const; 48*03ce13f7SAndroid Build Coastguard Worker bool isFloatFormat() const; 49*03ce13f7SAndroid Build Coastguard Worker bool isYcbcrFormat() const; 50*03ce13f7SAndroid Build Coastguard Worker 51*03ce13f7SAndroid Build Coastguard Worker bool isCompatible(Format other) const; 52*03ce13f7SAndroid Build Coastguard Worker std::vector<Format> getCompatibleFormats() const; 53*03ce13f7SAndroid Build Coastguard Worker 54*03ce13f7SAndroid Build Coastguard Worker bool isCompressed() const; 55*03ce13f7SAndroid Build Coastguard Worker VkFormat getDecompressedFormat() const; 56*03ce13f7SAndroid Build Coastguard Worker int blockWidth() const; 57*03ce13f7SAndroid Build Coastguard Worker int blockHeight() const; 58*03ce13f7SAndroid Build Coastguard Worker int bytesPerBlock() const; 59*03ce13f7SAndroid Build Coastguard Worker 60*03ce13f7SAndroid Build Coastguard Worker int componentCount() const; 61*03ce13f7SAndroid Build Coastguard Worker bool isUnsignedComponent(int component) const; 62*03ce13f7SAndroid Build Coastguard Worker 63*03ce13f7SAndroid Build Coastguard Worker size_t bytes() const; 64*03ce13f7SAndroid Build Coastguard Worker size_t pitchB(int width, int border) const; 65*03ce13f7SAndroid Build Coastguard Worker size_t sliceB(int width, int height, int border) const; 66*03ce13f7SAndroid Build Coastguard Worker 67*03ce13f7SAndroid Build Coastguard Worker sw::float4 getScale() const; 68*03ce13f7SAndroid Build Coastguard Worker 69*03ce13f7SAndroid Build Coastguard Worker sw::int4 bitsPerComponent() const; 70*03ce13f7SAndroid Build Coastguard Worker 71*03ce13f7SAndroid Build Coastguard Worker bool supportsColorAttachmentBlend() const; 72*03ce13f7SAndroid Build Coastguard Worker 73*03ce13f7SAndroid Build Coastguard Worker // Texture sampling utilities 74*03ce13f7SAndroid Build Coastguard Worker bool has16bitPackedTextureFormat() const; 75*03ce13f7SAndroid Build Coastguard Worker bool has8bitTextureComponents() const; 76*03ce13f7SAndroid Build Coastguard Worker bool has16bitTextureComponents() const; 77*03ce13f7SAndroid Build Coastguard Worker bool has32bitIntegerTextureComponents() const; 78*03ce13f7SAndroid Build Coastguard Worker bool isRGBComponent(int component) const; 79*03ce13f7SAndroid Build Coastguard Worker 80*03ce13f7SAndroid Build Coastguard Worker static uint8_t mapTo8bit(VkFormat format); 81*03ce13f7SAndroid Build Coastguard Worker static VkFormat mapFrom8bit(uint8_t format); 82*03ce13f7SAndroid Build Coastguard Worker 83*03ce13f7SAndroid Build Coastguard Worker private: 84*03ce13f7SAndroid Build Coastguard Worker VkFormat getCompatibilityClassRepresentative() const; 85*03ce13f7SAndroid Build Coastguard Worker size_t sliceBUnpadded(int width, int height, int border) const; 86*03ce13f7SAndroid Build Coastguard Worker 87*03ce13f7SAndroid Build Coastguard Worker VkFormat format = VK_FORMAT_UNDEFINED; 88*03ce13f7SAndroid Build Coastguard Worker }; 89*03ce13f7SAndroid Build Coastguard Worker 90*03ce13f7SAndroid Build Coastguard Worker } // namespace vk 91*03ce13f7SAndroid Build Coastguard Worker 92*03ce13f7SAndroid Build Coastguard Worker #endif // VK_FORMAT_HPP_ 93