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 #ifndef VK_SAMPLER_H
24 #define VK_SAMPLER_H
25
26 #include "vk_object.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 static inline bool
vk_border_color_is_custom(VkBorderColor color)33 vk_border_color_is_custom(VkBorderColor color)
34 {
35 return color == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT ||
36 color == VK_BORDER_COLOR_INT_CUSTOM_EXT;
37 }
38
39 VkClearColorValue vk_border_color_value(VkBorderColor color);
40 bool vk_border_color_is_int(VkBorderColor color);
41
42 VkClearColorValue
43 vk_sampler_border_color_value(const VkSamplerCreateInfo *pCreateInfo,
44 VkFormat *format_out);
45
46 struct vk_sampler {
47 struct vk_object_base base;
48
49 /** Format of paired image views or VK_FORMAT_UNDEFINED
50 *
51 * This is taken either from VkSamplerYcbcrConversionCreateInfo::format or
52 * VkSamplerCustomBorderColorCreateInfoEXT::format.
53 */
54 VkFormat format;
55
56 /** VkSamplerCreateInfo::borderColor */
57 VkBorderColor border_color;
58
59 /** Border color value
60 *
61 * If VkSamplerCreateInfo::borderColor is one of the Vulkan 1.0 enumerated
62 * border colors, this will be the VkClearColorValue representation of that
63 * value. VkSamplerCreateInfo::borderColor is VK_BORDER_COLOR_*_CUSTOM_EXT,
64 * this is VkSamplerCustomBorderColorCreateInfoEXT::customBorderColor.
65 */
66 VkClearColorValue border_color_value;
67
68 /**
69 * VkSamplerReductionModeCreateInfo::reductionMode or
70 * VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE.
71 */
72 VkSamplerReductionMode reduction_mode;
73
74 /** VkSamplerYcbcrConversionInfo::conversion or NULL
75 *
76 * We ensure that this is always NULL whenever vk_sampler::format is not a
77 * YCbCr format. This is important on Android where YCbCr conversion
78 * objects are required for all EXTERNAL formats, even if they are not
79 * YCbCr formats.
80 */
81 struct vk_ycbcr_conversion *ycbcr_conversion;
82 };
83 VK_DEFINE_NONDISP_HANDLE_CASTS(vk_sampler, base, VkSampler,
84 VK_OBJECT_TYPE_SAMPLER);
85
86 void *vk_sampler_create(struct vk_device *device,
87 const VkSamplerCreateInfo *pCreateInfo,
88 const VkAllocationCallbacks *alloc,
89 size_t size);
90 void vk_sampler_destroy(struct vk_device *device,
91 const VkAllocationCallbacks *alloc,
92 struct vk_sampler *sampler);
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 #endif /* VK_SAMPLER_H */
99