Path: blob/21.2-virgl/src/freedreno/vulkan/vk_format.h
4565 views
/*1* Copyright © 2016 Red Hat.2* Copyright © 2016 Bas Nieuwenhuizen3*4* Based on u_format.h which is:5* Copyright 2009-2010 VMware, Inc.6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the "Software"),8* to deal in the Software without restriction, including without limitation9* the rights to use, copy, modify, merge, publish, distribute, sublicense,10* and/or sell copies of the Software, and to permit persons to whom the11* Software is furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice (including the next14* paragraph) shall be included in all copies or substantial portions of the15* Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR18* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL20* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER21* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING22* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER23* DEALINGS IN THE SOFTWARE.24*/2526#ifndef VK_FORMAT_H27#define VK_FORMAT_H2829#include <assert.h>30#include <util/macros.h>31#include <util/format/u_format.h>32#include <vulkan/util/vk_format.h>3334#include <vulkan/vulkan.h>3536static inline const struct util_format_description *37vk_format_description(VkFormat format)38{39return util_format_description(vk_format_to_pipe_format(format));40}4142/**43* Return bytes per block (not pixel) for the given format.44*/45static inline unsigned46vk_format_get_blocksize(VkFormat format)47{48return util_format_get_blocksize(vk_format_to_pipe_format(format));49}5051static inline unsigned52vk_format_get_blockwidth(VkFormat format)53{54return util_format_get_blockwidth(vk_format_to_pipe_format(format));55}5657static inline unsigned58vk_format_get_blockheight(VkFormat format)59{60return util_format_get_blockheight(vk_format_to_pipe_format(format));61}6263static inline bool64vk_format_is_compressed(VkFormat format)65{66/* this includes 4:2:2 formats, which are compressed formats for vulkan */67return vk_format_get_blockwidth(format) > 1;68}6970static inline bool71vk_format_has_alpha(VkFormat format)72{73return util_format_has_alpha(vk_format_to_pipe_format(format));74}7576static inline bool77vk_format_is_int(VkFormat format)78{79return util_format_is_pure_integer(vk_format_to_pipe_format(format));80}8182static inline bool83vk_format_is_uint(VkFormat format)84{85return util_format_is_pure_uint(vk_format_to_pipe_format(format));86}8788static inline bool89vk_format_is_sint(VkFormat format)90{91return util_format_is_pure_sint(vk_format_to_pipe_format(format));92}9394static inline bool95vk_format_is_srgb(VkFormat format)96{97return util_format_is_srgb(vk_format_to_pipe_format(format));98}99100static inline bool101vk_format_is_unorm(VkFormat format)102{103return util_format_is_unorm(vk_format_to_pipe_format(format));104}105106static inline bool107vk_format_is_snorm(VkFormat format)108{109return util_format_is_snorm(vk_format_to_pipe_format(format));110}111112static inline bool113vk_format_is_float(VkFormat format)114{115return util_format_is_float(vk_format_to_pipe_format(format));116}117118static inline unsigned119vk_format_get_component_bits(VkFormat format,120enum util_format_colorspace colorspace,121unsigned component)122{123switch (format) {124case VK_FORMAT_G8B8G8R8_422_UNORM:125case VK_FORMAT_B8G8R8G8_422_UNORM:126case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:127case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:128/* util_format_get_component_bits doesn't return what we want */129return 8;130default:131break;132}133134return util_format_get_component_bits(vk_format_to_pipe_format(format),135colorspace, component);136}137138static inline unsigned139vk_format_get_nr_components(VkFormat format)140{141return util_format_get_nr_components(vk_format_to_pipe_format(format));142}143144#endif /* VK_FORMAT_H */145146147