1 /*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 *
5 * Based on u_format.h which is:
6 * Copyright 2009-2010 VMware, Inc.
7 *
8 * SPDX-License-Identifier: MIT
9 */
10
11 #ifndef RADV_FORMATS_H
12 #define RADV_FORMATS_H
13
14 #include <assert.h>
15 #include <util/macros.h>
16 #include <vulkan/vulkan.h>
17
18 #include "amd_family.h"
19
20 #include "vk_format.h"
21
22 /**
23 * Return the index of the first non-void channel
24 * -1 if no non-void channels
25 */
26 static inline int
vk_format_get_first_non_void_channel(VkFormat format)27 vk_format_get_first_non_void_channel(VkFormat format)
28 {
29 return util_format_get_first_non_void_channel(vk_format_to_pipe_format(format));
30 }
31
32 static inline enum pipe_swizzle
radv_swizzle_conv(VkComponentSwizzle component,const unsigned char chan[4],VkComponentSwizzle vk_swiz)33 radv_swizzle_conv(VkComponentSwizzle component, const unsigned char chan[4], VkComponentSwizzle vk_swiz)
34 {
35 if (vk_swiz == VK_COMPONENT_SWIZZLE_IDENTITY)
36 vk_swiz = component;
37 switch (vk_swiz) {
38 case VK_COMPONENT_SWIZZLE_ZERO:
39 return PIPE_SWIZZLE_0;
40 case VK_COMPONENT_SWIZZLE_ONE:
41 return PIPE_SWIZZLE_1;
42 case VK_COMPONENT_SWIZZLE_R:
43 case VK_COMPONENT_SWIZZLE_G:
44 case VK_COMPONENT_SWIZZLE_B:
45 case VK_COMPONENT_SWIZZLE_A:
46 return (enum pipe_swizzle)chan[vk_swiz - VK_COMPONENT_SWIZZLE_R];
47 default:
48 unreachable("Illegal swizzle");
49 }
50 }
51
52 static inline void
vk_format_compose_swizzles(const VkComponentMapping * mapping,const unsigned char swz[4],enum pipe_swizzle dst[4])53 vk_format_compose_swizzles(const VkComponentMapping *mapping, const unsigned char swz[4], enum pipe_swizzle dst[4])
54 {
55 dst[0] = radv_swizzle_conv(VK_COMPONENT_SWIZZLE_R, swz, mapping->r);
56 dst[1] = radv_swizzle_conv(VK_COMPONENT_SWIZZLE_G, swz, mapping->g);
57 dst[2] = radv_swizzle_conv(VK_COMPONENT_SWIZZLE_B, swz, mapping->b);
58 dst[3] = radv_swizzle_conv(VK_COMPONENT_SWIZZLE_A, swz, mapping->a);
59 }
60
61 static inline bool
vk_format_is_subsampled(VkFormat format)62 vk_format_is_subsampled(VkFormat format)
63 {
64 return util_format_is_subsampled_422(vk_format_to_pipe_format(format));
65 }
66
67 static inline VkFormat
vk_format_no_srgb(VkFormat format)68 vk_format_no_srgb(VkFormat format)
69 {
70 switch (format) {
71 case VK_FORMAT_R8_SRGB:
72 return VK_FORMAT_R8_UNORM;
73 case VK_FORMAT_R8G8_SRGB:
74 return VK_FORMAT_R8G8_UNORM;
75 case VK_FORMAT_R8G8B8_SRGB:
76 return VK_FORMAT_R8G8B8_UNORM;
77 case VK_FORMAT_B8G8R8_SRGB:
78 return VK_FORMAT_B8G8R8_UNORM;
79 case VK_FORMAT_R8G8B8A8_SRGB:
80 return VK_FORMAT_R8G8B8A8_UNORM;
81 case VK_FORMAT_B8G8R8A8_SRGB:
82 return VK_FORMAT_B8G8R8A8_UNORM;
83 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
84 return VK_FORMAT_A8B8G8R8_UNORM_PACK32;
85 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
86 return VK_FORMAT_BC1_RGB_UNORM_BLOCK;
87 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
88 return VK_FORMAT_BC1_RGBA_UNORM_BLOCK;
89 case VK_FORMAT_BC2_SRGB_BLOCK:
90 return VK_FORMAT_BC2_UNORM_BLOCK;
91 case VK_FORMAT_BC3_SRGB_BLOCK:
92 return VK_FORMAT_BC3_UNORM_BLOCK;
93 case VK_FORMAT_BC7_SRGB_BLOCK:
94 return VK_FORMAT_BC7_UNORM_BLOCK;
95 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
96 return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
97 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
98 return VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK;
99 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
100 return VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
101 default:
102 assert(!vk_format_is_srgb(format));
103 return format;
104 }
105 }
106
107 struct radv_physical_device;
108
109 uint32_t radv_translate_buffer_numformat(const struct util_format_description *desc, int first_non_void);
110
111 uint32_t radv_translate_tex_dataformat(const struct radv_physical_device *pdev,
112 const struct util_format_description *desc, int first_non_void);
113
114 uint32_t radv_translate_tex_numformat(const struct util_format_description *desc, int first_non_void);
115
116 bool radv_is_atomic_format_supported(VkFormat format);
117
118 bool radv_is_storage_image_format_supported(const struct radv_physical_device *dev, VkFormat format);
119
120 bool radv_is_buffer_format_supported(VkFormat format, bool *scaled);
121
122 bool radv_is_colorbuffer_format_supported(const struct radv_physical_device *pdev, VkFormat format);
123
124 bool radv_is_format_emulated(const struct radv_physical_device *pdev, VkFormat format);
125
126 bool radv_format_pack_clear_color(VkFormat format, uint32_t clear_vals[2], VkClearColorValue *value);
127
128 bool radv_dcc_formats_compatible(enum amd_gfx_level gfx_level, VkFormat format1, VkFormat format2,
129 bool *sign_reinterpret);
130
131 #endif /* RADV_FORMATS_H */
132