1 /*
2 * Copyright © 2023 Imagination Technologies Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * 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 THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #ifndef PVR_BORDER_H
25 #define PVR_BORDER_H
26
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include <vulkan/vulkan_core.h>
30
31 #include "pvr_csb.h"
32 #include "util/bitset.h"
33
34 #define PVR_BORDER_COLOR_TABLE_NR_ENTRIES \
35 (PVRX(TEXSTATE_SAMPLER_BORDERCOLOR_INDEX_MAX_SIZE) + 1)
36
37 #define PVR_BORDER_COLOR_TABLE_NR_BUILTIN_ENTRIES \
38 (VK_BORDER_COLOR_INT_OPAQUE_WHITE + 1)
39
40 #define PVR_BORDER_COLOR_TABLE_NR_CUSTOM_ENTRIES \
41 (PVR_BORDER_COLOR_TABLE_NR_ENTRIES - \
42 PVR_BORDER_COLOR_TABLE_NR_BUILTIN_ENTRIES)
43
44 /* Forward declaration from "pvr_common.h" */
45 struct pvr_sampler;
46
47 /* Forward declaration from "pvr_bo.h" */
48 struct pvr_bo;
49
50 /* Forward declaration from "pvr_private.h" */
51 struct pvr_device;
52
53 struct pvr_border_color_table {
54 BITSET_DECLARE(unused_entries, PVR_BORDER_COLOR_TABLE_NR_ENTRIES);
55
56 /* Contains an array of:
57 * PVR_BORDER_COLOR_TABLE_NR_ENTRIES x struct pvr_border_color_table_entry
58 */
59 struct pvr_bo *table;
60 };
61
62 VkResult pvr_border_color_table_init(struct pvr_border_color_table *table,
63 struct pvr_device *device);
64 void pvr_border_color_table_finish(struct pvr_border_color_table *table,
65 struct pvr_device *device);
66
67 VkResult
68 pvr_border_color_table_get_or_create_entry(struct pvr_border_color_table *table,
69 const struct pvr_sampler *sampler,
70 uint32_t *index_out);
71
pvr_border_color_table_is_index_valid(const struct pvr_border_color_table * const table,const uint32_t index)72 static inline bool pvr_border_color_table_is_index_valid(
73 const struct pvr_border_color_table *const table,
74 const uint32_t index)
75 {
76 return !BITSET_TEST(table->unused_entries, index);
77 }
78
79 #endif /* PVR_BORDER_H */
80