1 /*
2 * Copyright © 2022 Collabora, LTD
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "vk_sampler.h"
25 #include "vk_util.h"
26
27 VkClearColorValue
vk_border_color_value(VkBorderColor color)28 vk_border_color_value(VkBorderColor color)
29 {
30 switch (color) {
31 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK:
32 return (VkClearColorValue) { .float32 = { 0, 0, 0, 0 } };
33 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK:
34 return (VkClearColorValue) { .int32 = { 0, 0, 0, 0 } };
35 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK:
36 return (VkClearColorValue) { .float32 = { 0, 0, 0, 1 } };
37 case VK_BORDER_COLOR_INT_OPAQUE_BLACK:
38 return (VkClearColorValue) { .int32 = { 0, 0, 0, 1 } };
39 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE:
40 return (VkClearColorValue) { .float32 = { 1, 1, 1, 1 } };
41 case VK_BORDER_COLOR_INT_OPAQUE_WHITE:
42 return (VkClearColorValue) { .int32 = { 1, 1, 1, 1 } };
43 default:
44 unreachable("Invalid or custom border color enum");
45 }
46 }
47
48 bool
vk_border_color_is_int(VkBorderColor color)49 vk_border_color_is_int(VkBorderColor color)
50 {
51 switch (color) {
52 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK:
53 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK:
54 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE:
55 case VK_BORDER_COLOR_FLOAT_CUSTOM_EXT:
56 return false;
57 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK:
58 case VK_BORDER_COLOR_INT_OPAQUE_BLACK:
59 case VK_BORDER_COLOR_INT_OPAQUE_WHITE:
60 case VK_BORDER_COLOR_INT_CUSTOM_EXT:
61 return true;
62 default:
63 unreachable("Invalid border color enum");
64 }
65 }
66
67 VkClearColorValue
vk_sampler_border_color_value(const VkSamplerCreateInfo * pCreateInfo,VkFormat * format_out)68 vk_sampler_border_color_value(const VkSamplerCreateInfo *pCreateInfo,
69 VkFormat *format_out)
70 {
71 if (pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT ||
72 pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT) {
73 const VkSamplerCustomBorderColorCreateInfoEXT *border_color_info =
74 vk_find_struct_const(pCreateInfo->pNext,
75 SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT);
76 if (format_out)
77 *format_out = border_color_info->format;
78
79 return border_color_info->customBorderColor;
80 } else {
81 if (format_out)
82 *format_out = VK_FORMAT_UNDEFINED;
83
84 return vk_border_color_value(pCreateInfo->borderColor);
85 }
86 }
87
88