1361fc4cbSmaya/*
2361fc4cbSmaya * Copyright © 2016 Red Hat.
3361fc4cbSmaya * Copyright © 2016 Bas Nieuwenhuizen
4361fc4cbSmaya *
5361fc4cbSmaya * Based on u_format.h which is:
67ec681f3Smrg * Copyright 2009-2010 VMware, Inc.
7361fc4cbSmaya * Permission is hereby granted, free of charge, to any person obtaining a
8361fc4cbSmaya * copy of this software and associated documentation files (the "Software"),
9361fc4cbSmaya * to deal in the Software without restriction, including without limitation
10361fc4cbSmaya * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11361fc4cbSmaya * and/or sell copies of the Software, and to permit persons to whom the
12361fc4cbSmaya * Software is furnished to do so, subject to the following conditions:
13361fc4cbSmaya *
14361fc4cbSmaya * The above copyright notice and this permission notice (including the next
15361fc4cbSmaya * paragraph) shall be included in all copies or substantial portions of the
16361fc4cbSmaya * Software.
17361fc4cbSmaya *
18361fc4cbSmaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19361fc4cbSmaya * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20361fc4cbSmaya * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21361fc4cbSmaya * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22361fc4cbSmaya * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23361fc4cbSmaya * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24361fc4cbSmaya * DEALINGS IN THE SOFTWARE.
25361fc4cbSmaya */
26361fc4cbSmaya
27361fc4cbSmaya#ifndef VK_FORMAT_H
28361fc4cbSmaya#define VK_FORMAT_H
29361fc4cbSmaya
30361fc4cbSmaya#include <assert.h>
31361fc4cbSmaya#include <util/macros.h>
327ec681f3Smrg#include <util/format/u_format.h>
337ec681f3Smrg#include <vulkan/util/vk_format.h>
34361fc4cbSmaya
35361fc4cbSmaya#include <vulkan/vulkan.h>
36361fc4cbSmaya
377ec681f3Smrgstatic inline const struct util_format_description *
387ec681f3Smrgvk_format_description(VkFormat format)
39361fc4cbSmaya{
407ec681f3Smrg   return util_format_description(vk_format_to_pipe_format(format));
41361fc4cbSmaya}
42361fc4cbSmaya
43361fc4cbSmaya/**
44361fc4cbSmaya * Return bytes per block (not pixel) for the given format.
45361fc4cbSmaya */
46361fc4cbSmayastatic inline unsigned
47361fc4cbSmayavk_format_get_blocksize(VkFormat format)
48361fc4cbSmaya{
497ec681f3Smrg   return util_format_get_blocksize(vk_format_to_pipe_format(format));
50361fc4cbSmaya}
51361fc4cbSmaya
52361fc4cbSmayastatic inline unsigned
53361fc4cbSmayavk_format_get_blockwidth(VkFormat format)
54361fc4cbSmaya{
557ec681f3Smrg   return util_format_get_blockwidth(vk_format_to_pipe_format(format));
56361fc4cbSmaya}
57361fc4cbSmaya
58361fc4cbSmayastatic inline unsigned
59361fc4cbSmayavk_format_get_blockheight(VkFormat format)
60361fc4cbSmaya{
617ec681f3Smrg   return util_format_get_blockheight(vk_format_to_pipe_format(format));
62361fc4cbSmaya}
63361fc4cbSmaya
64361fc4cbSmayastatic inline bool
65361fc4cbSmayavk_format_is_compressed(VkFormat format)
66361fc4cbSmaya{
677ec681f3Smrg   /* this includes 4:2:2 formats, which are compressed formats for vulkan */
687ec681f3Smrg   return vk_format_get_blockwidth(format) > 1;
69361fc4cbSmaya}
70361fc4cbSmaya
71361fc4cbSmayastatic inline bool
727ec681f3Smrgvk_format_has_alpha(VkFormat format)
73361fc4cbSmaya{
747ec681f3Smrg   return util_format_has_alpha(vk_format_to_pipe_format(format));
75361fc4cbSmaya}
76361fc4cbSmaya
77361fc4cbSmayastatic inline bool
787ec681f3Smrgvk_format_is_int(VkFormat format)
79361fc4cbSmaya{
807ec681f3Smrg   return util_format_is_pure_integer(vk_format_to_pipe_format(format));
81361fc4cbSmaya}
82361fc4cbSmaya
83361fc4cbSmayastatic inline bool
847ec681f3Smrgvk_format_is_uint(VkFormat format)
85361fc4cbSmaya{
867ec681f3Smrg   return util_format_is_pure_uint(vk_format_to_pipe_format(format));
87361fc4cbSmaya}
88361fc4cbSmaya
89361fc4cbSmayastatic inline bool
907ec681f3Smrgvk_format_is_sint(VkFormat format)
91361fc4cbSmaya{
927ec681f3Smrg   return util_format_is_pure_sint(vk_format_to_pipe_format(format));
93361fc4cbSmaya}
94361fc4cbSmaya
95361fc4cbSmayastatic inline bool
967ec681f3Smrgvk_format_is_srgb(VkFormat format)
97361fc4cbSmaya{
987ec681f3Smrg   return util_format_is_srgb(vk_format_to_pipe_format(format));
99361fc4cbSmaya}
100361fc4cbSmaya
101361fc4cbSmayastatic inline bool
1027ec681f3Smrgvk_format_is_unorm(VkFormat format)
103361fc4cbSmaya{
1047ec681f3Smrg   return util_format_is_unorm(vk_format_to_pipe_format(format));
105361fc4cbSmaya}
106361fc4cbSmaya
107361fc4cbSmayastatic inline bool
1087ec681f3Smrgvk_format_is_snorm(VkFormat format)
109361fc4cbSmaya{
1107ec681f3Smrg   return util_format_is_snorm(vk_format_to_pipe_format(format));
111361fc4cbSmaya}
112361fc4cbSmaya
113361fc4cbSmayastatic inline bool
1147ec681f3Smrgvk_format_is_float(VkFormat format)
115361fc4cbSmaya{
1167ec681f3Smrg   return util_format_is_float(vk_format_to_pipe_format(format));
117361fc4cbSmaya}
118361fc4cbSmaya
119361fc4cbSmayastatic inline unsigned
120361fc4cbSmayavk_format_get_component_bits(VkFormat format,
1217ec681f3Smrg                             enum util_format_colorspace colorspace,
122361fc4cbSmaya                             unsigned component)
123361fc4cbSmaya{
124361fc4cbSmaya   switch (format) {
1257ec681f3Smrg   case VK_FORMAT_G8B8G8R8_422_UNORM:
1267ec681f3Smrg   case VK_FORMAT_B8G8R8G8_422_UNORM:
1277ec681f3Smrg   case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
1287ec681f3Smrg   case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
1297ec681f3Smrg      /* util_format_get_component_bits doesn't return what we want */
1307ec681f3Smrg      return 8;
131361fc4cbSmaya   default:
1327ec681f3Smrg      break;
133361fc4cbSmaya   }
1347ec681f3Smrg
1357ec681f3Smrg   return util_format_get_component_bits(vk_format_to_pipe_format(format),
1367ec681f3Smrg                                         colorspace, component);
137361fc4cbSmaya}
138361fc4cbSmaya
139361fc4cbSmayastatic inline unsigned
140361fc4cbSmayavk_format_get_nr_components(VkFormat format)
141361fc4cbSmaya{
1427ec681f3Smrg   return util_format_get_nr_components(vk_format_to_pipe_format(format));
143361fc4cbSmaya}
144361fc4cbSmaya
145361fc4cbSmaya#endif /* VK_FORMAT_H */
146