virgl: track valid buffer range for transfer sync
[mesa.git] / src / gallium / drivers / virgl / virgl_winsys.h
1 /*
2 * Copyright 2014, 2015 Red Hat.
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #ifndef VIRGL_WINSYS_H
24 #define VIRGL_WINSYS_H
25
26 #include "pipe/p_defines.h"
27 #include "virgl_hw.h"
28
29 struct pipe_box;
30 struct pipe_fence_handle;
31 struct winsys_handle;
32 struct virgl_hw_res;
33
34 #define VIRGL_MAX_TBUF_DWORDS 1024
35 #define VIRGL_MAX_CMDBUF_DWORDS ((64 * 1024) + VIRGL_MAX_TBUF_DWORDS)
36
37 struct virgl_drm_caps {
38 union virgl_caps caps;
39 };
40
41 struct virgl_cmd_buf {
42 unsigned cdw;
43 uint32_t *buf;
44 };
45
46 struct virgl_winsys {
47 unsigned pci_id;
48 int supports_fences; /* In/Out fences are supported */
49 int supports_encoded_transfers; /* Encoded transfers are supported */
50
51 void (*destroy)(struct virgl_winsys *vws);
52
53 int (*transfer_put)(struct virgl_winsys *vws,
54 struct virgl_hw_res *res,
55 const struct pipe_box *box,
56 uint32_t stride, uint32_t layer_stride,
57 uint32_t buf_offset, uint32_t level);
58
59 int (*transfer_get)(struct virgl_winsys *vws,
60 struct virgl_hw_res *res,
61 const struct pipe_box *box,
62 uint32_t stride, uint32_t layer_stride,
63 uint32_t buf_offset, uint32_t level);
64
65 struct virgl_hw_res *(*resource_create)(struct virgl_winsys *vws,
66 enum pipe_texture_target target,
67 uint32_t format, uint32_t bind,
68 uint32_t width, uint32_t height,
69 uint32_t depth, uint32_t array_size,
70 uint32_t last_level, uint32_t nr_samples,
71 uint32_t size);
72
73 void (*resource_unref)(struct virgl_winsys *vws, struct virgl_hw_res *res);
74
75 void *(*resource_map)(struct virgl_winsys *vws, struct virgl_hw_res *res);
76 void (*resource_wait)(struct virgl_winsys *vws, struct virgl_hw_res *res);
77 boolean (*resource_is_busy)(struct virgl_winsys *vws,
78 struct virgl_hw_res *res);
79
80 struct virgl_hw_res *(*resource_create_from_handle)(struct virgl_winsys *vws,
81 struct winsys_handle *whandle);
82 boolean (*resource_get_handle)(struct virgl_winsys *vws,
83 struct virgl_hw_res *res,
84 uint32_t stride,
85 struct winsys_handle *whandle);
86
87 struct virgl_cmd_buf *(*cmd_buf_create)(struct virgl_winsys *ws, uint32_t size);
88 void (*cmd_buf_destroy)(struct virgl_cmd_buf *buf);
89
90 void (*emit_res)(struct virgl_winsys *vws, struct virgl_cmd_buf *buf, struct virgl_hw_res *res, boolean write_buffer);
91 int (*submit_cmd)(struct virgl_winsys *vws, struct virgl_cmd_buf *buf,
92 struct pipe_fence_handle **fence);
93
94 boolean (*res_is_referenced)(struct virgl_winsys *vws,
95 struct virgl_cmd_buf *buf,
96 struct virgl_hw_res *res);
97
98 int (*get_caps)(struct virgl_winsys *vws, struct virgl_drm_caps *caps);
99
100 /* fence */
101 struct pipe_fence_handle *(*cs_create_fence)(struct virgl_winsys *vws, int fd);
102 bool (*fence_wait)(struct virgl_winsys *vws,
103 struct pipe_fence_handle *fence,
104 uint64_t timeout);
105
106 void (*fence_reference)(struct virgl_winsys *vws,
107 struct pipe_fence_handle **dst,
108 struct pipe_fence_handle *src);
109
110 /* for sw paths */
111 void (*flush_frontbuffer)(struct virgl_winsys *vws,
112 struct virgl_hw_res *res,
113 unsigned level, unsigned layer,
114 void *winsys_drawable_handle,
115 struct pipe_box *sub_box);
116 void (*fence_server_sync)(struct virgl_winsys *vws,
117 struct virgl_cmd_buf *cbuf,
118 struct pipe_fence_handle *fence);
119
120 int (*fence_get_fd)(struct virgl_winsys *vws,
121 struct pipe_fence_handle *fence);
122 };
123
124 /* this defaults all newer caps,
125 * the kernel will overwrite these if newer version is available.
126 */
127 static inline void virgl_ws_fill_new_caps_defaults(struct virgl_drm_caps *caps)
128 {
129 caps->caps.v2.min_aliased_point_size = 1.f;
130 caps->caps.v2.max_aliased_point_size = 255.f;
131 caps->caps.v2.min_smooth_point_size = 1.f;
132 caps->caps.v2.max_smooth_point_size = 190.f;
133 caps->caps.v2.min_aliased_line_width = 1.f;
134 caps->caps.v2.max_aliased_line_width = 10.f;
135 caps->caps.v2.min_smooth_line_width = 0.f;
136 caps->caps.v2.max_smooth_line_width = 10.f;
137 caps->caps.v2.max_texture_lod_bias = 15.0f;
138 caps->caps.v2.max_geom_output_vertices = 256;
139 caps->caps.v2.max_geom_total_output_components = 1024;
140 caps->caps.v2.max_vertex_outputs = 32;
141 caps->caps.v2.max_vertex_attribs = 16;
142 caps->caps.v2.max_shader_patch_varyings = 30;
143 caps->caps.v2.min_texel_offset = -8;
144 caps->caps.v2.max_texel_offset = 7;
145 caps->caps.v2.min_texture_gather_offset = -8;
146 caps->caps.v2.max_texture_gather_offset = 7;
147 caps->caps.v2.texture_buffer_offset_alignment = 0;
148 caps->caps.v2.uniform_buffer_offset_alignment = 256;
149 caps->caps.v2.shader_buffer_offset_alignment = 32;
150 caps->caps.v2.capability_bits = 0;
151 caps->caps.v2.max_vertex_attrib_stride = 0;
152 caps->caps.v2.max_image_samples = 0;
153 caps->caps.v2.max_compute_work_group_invocations = 0;
154 caps->caps.v2.max_compute_shared_memory_size = 0;
155 caps->caps.v2.host_feature_check_version = 0;
156 }
157 #endif