1 /*
2 * Copyright © 2021 Valve Corporation
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 * Authors:
24 * Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
25 */
26
27 #ifndef ZINK_KOPPER_H
28 #define ZINK_KOPPER_H
29
30 #include "kopper_interface.h"
31
32 struct kopper_swapchain_image {
33 bool init;
34 bool acquired;
35 bool dt_has_data;
36 int age;
37 VkImage image;
38 VkSemaphore acquire;
39 };
40
41 struct kopper_swapchain {
42 struct kopper_swapchain *next;
43 VkSwapchainKHR swapchain;
44
45 unsigned last_present;
46 unsigned num_images;
47 uint32_t last_present_prune;
48 struct hash_table *presents;
49 VkSwapchainCreateInfoKHR scci;
50 unsigned num_acquires;
51 unsigned max_acquires;
52 unsigned async_presents;
53 struct kopper_swapchain_image *images;
54 };
55
56 enum kopper_type {
57 KOPPER_X11,
58 KOPPER_WAYLAND,
59 KOPPER_WIN32
60 };
61
62 struct kopper_displaytarget
63 {
64 unsigned refcount;
65 VkFormat formats[2];
66 unsigned width;
67 unsigned height;
68 unsigned stride;
69 void *loader_private;
70
71 VkSurfaceKHR surface;
72 uint32_t present_modes; //VkPresentModeKHR bitmask
73 struct kopper_swapchain *swapchain;
74 struct kopper_swapchain *old_swapchain;
75
76 struct kopper_loader_info info;
77 struct util_queue_fence present_fence;
78
79 VkSurfaceCapabilitiesKHR caps;
80 VkImageFormatListCreateInfo format_list;
81 enum kopper_type type;
82 bool is_kill;
83 VkPresentModeKHR present_mode;
84 };
85
86 struct zink_context;
87 struct zink_screen;
88 struct zink_resource;
89
90 static inline bool
zink_kopper_has_srgb(const struct kopper_displaytarget * cdt)91 zink_kopper_has_srgb(const struct kopper_displaytarget *cdt)
92 {
93 return cdt->formats[1] != VK_FORMAT_UNDEFINED;
94 }
95
96 static inline bool
zink_kopper_last_present_eq(const struct kopper_displaytarget * cdt,uint32_t idx)97 zink_kopper_last_present_eq(const struct kopper_displaytarget *cdt, uint32_t idx)
98 {
99 return cdt->swapchain->last_present == idx;
100 }
101
102 static inline bool
zink_kopper_acquired(const struct kopper_displaytarget * cdt,uint32_t idx)103 zink_kopper_acquired(const struct kopper_displaytarget *cdt, uint32_t idx)
104 {
105 return idx != UINT32_MAX && cdt->swapchain->images[idx].acquired;
106 }
107
108 struct kopper_displaytarget *
109 zink_kopper_displaytarget_create(struct zink_screen *screen, unsigned tex_usage,
110 enum pipe_format format, unsigned width,
111 unsigned height, unsigned alignment,
112 const void *loader_private, unsigned *stride);
113 void
114 zink_kopper_displaytarget_destroy(struct zink_screen *screen, struct kopper_displaytarget *cdt);
115
116
117 bool
118 zink_kopper_acquire(struct zink_context *ctx, struct zink_resource *res, uint64_t timeout);
119 VkSemaphore
120 zink_kopper_acquire_submit(struct zink_screen *screen, struct zink_resource *res);
121 VkSemaphore
122 zink_kopper_present(struct zink_screen *screen, struct zink_resource *res);
123 void
124 zink_kopper_present_queue(struct zink_screen *screen, struct zink_resource *res);
125 bool
126 zink_kopper_acquire_readback(struct zink_context *ctx, struct zink_resource *res);
127 bool
128 zink_kopper_present_readback(struct zink_context *ctx, struct zink_resource *res);
129 void
130 zink_kopper_deinit_displaytarget(struct zink_screen *screen, struct kopper_displaytarget *cdt);
131 bool
132 zink_kopper_update(struct pipe_screen *pscreen, struct pipe_resource *pres, int *w, int *h);
133 bool
134 zink_kopper_is_cpu(const struct pipe_screen *pscreen);
135 void
136 zink_kopper_fixup_depth_buffer(struct zink_context *ctx);
137 bool
138 zink_kopper_check(struct pipe_resource *pres);
139 void
140 zink_kopper_set_swap_interval(struct pipe_screen *pscreen, struct pipe_resource *pres, int interval);
141 int
142 zink_kopper_query_buffer_age(struct pipe_context *pctx, struct pipe_resource *pres);
143 #endif
144