76d401b5c12608e91d3e426a97545003359e82f5
[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_compiler.h"
27
28 struct winsys_handle;
29 struct virgl_hw_res;
30
31 #define VIRGL_MAX_CMDBUF_DWORDS (16*1024)
32
33 struct virgl_drm_caps {
34 union virgl_caps caps;
35 };
36
37 struct virgl_cmd_buf {
38 unsigned cdw;
39 uint32_t *buf;
40 };
41
42 struct virgl_winsys {
43 unsigned pci_id;
44
45 void (*destroy)(struct virgl_winsys *vws);
46
47 int (*transfer_put)(struct virgl_winsys *vws,
48 struct virgl_hw_res *res,
49 const struct pipe_box *box,
50 uint32_t stride, uint32_t layer_stride,
51 uint32_t buf_offset, uint32_t level);
52
53 int (*transfer_get)(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 struct virgl_hw_res *(*resource_create)(struct virgl_winsys *vws,
60 enum pipe_texture_target target,
61 uint32_t format, uint32_t bind,
62 uint32_t width, uint32_t height,
63 uint32_t depth, uint32_t array_size,
64 uint32_t last_level, uint32_t nr_samples,
65 uint32_t size);
66
67 void (*resource_unref)(struct virgl_winsys *vws, struct virgl_hw_res *res);
68
69 void *(*resource_map)(struct virgl_winsys *vws, struct virgl_hw_res *res);
70 void (*resource_wait)(struct virgl_winsys *vws, struct virgl_hw_res *res);
71
72 struct virgl_hw_res *(*resource_create_from_handle)(struct virgl_winsys *vws,
73 struct winsys_handle *whandle);
74 boolean (*resource_get_handle)(struct virgl_winsys *vws,
75 struct virgl_hw_res *res,
76 uint32_t stride,
77 struct winsys_handle *whandle);
78
79 struct virgl_cmd_buf *(*cmd_buf_create)(struct virgl_winsys *ws);
80 void (*cmd_buf_destroy)(struct virgl_cmd_buf *buf);
81
82 void (*emit_res)(struct virgl_winsys *vws, struct virgl_cmd_buf *buf, struct virgl_hw_res *res, boolean write_buffer);
83 int (*submit_cmd)(struct virgl_winsys *vws, struct virgl_cmd_buf *buf);
84
85 boolean (*res_is_referenced)(struct virgl_winsys *vws,
86 struct virgl_cmd_buf *buf,
87 struct virgl_hw_res *res);
88
89 int (*get_caps)(struct virgl_winsys *vws, struct virgl_drm_caps *caps);
90
91 /* fence */
92 struct pipe_fence_handle *(*cs_create_fence)(struct virgl_winsys *vws);
93 bool (*fence_wait)(struct virgl_winsys *vws,
94 struct pipe_fence_handle *fence,
95 uint64_t timeout);
96
97 void (*fence_reference)(struct virgl_winsys *vws,
98 struct pipe_fence_handle **dst,
99 struct pipe_fence_handle *src);
100
101 /* for sw paths */
102 void (*flush_frontbuffer)(struct virgl_winsys *vws,
103 struct virgl_hw_res *res,
104 unsigned level, unsigned layer,
105 void *winsys_drawable_handle,
106 struct pipe_box *sub_box);
107 };
108
109
110 #endif