Debian Codegraph @

src/gallium/winsys/virgl/drm/virgl_drm_winsys.h

raw
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_DRM_WINSYS_H
24 #define VIRGL_DRM_WINSYS_H
25
26 #include <stdint.h>
27 #include "util/u_thread.h"
28 #include "pipe/p_state.h"
29 #include "util/list.h"
30
31 #include "virgl/virgl_winsys.h"
32 #include "virgl_resource_cache.h"
33
34 struct pipe_fence_handle;
35 struct hash_table;
36
37 struct virgl_hw_res {
38 struct pipe_reference reference;
39 enum pipe_texture_target target;
40 uint32_t res_handle;
41 uint32_t bo_handle;
42 int num_cs_references;
43 uint32_t size;
44 void *ptr;
45
46 struct virgl_resource_cache_entry cache_entry;
47 uint32_t bind;
48 uint32_t flags;
49 uint32_t flink_name;
50
51 /* We are not holding a lock when releasing references of the
52 * resource (intentionally) so we might start destroying it in one thread
53 * while briefly increasing the reference in another one leading to the
54 * free function being called twice, this ensures that it will be only
55 * called once. */
56 int needed_references;
57
58 /* false when the resource is known to be typed */
59 bool maybe_untyped;
60
61 /* true when the resource is imported or exported */
62 int external;
63
64 /* false when the resource is known to be idle */
65 int maybe_busy;
66 uint32_t blob_mem;
67 };
68
69
70 struct param {
71 uint64_t param;
72 const char *name;
73 uint64_t value;
74 };
75
76 enum param_id {
77 param_3d_features,
78 param_capset_fix,
79 param_resource_blob,
80 param_host_visible,
81 param_cross_device,
82 param_context_init,
83 param_supported_capset_ids,
84 param_max,
85 };
86
87 #define PARAM(x) (struct param) { x, #x, 0 }
88
89 struct param params[] = { PARAM(VIRTGPU_PARAM_3D_FEATURES),
90 PARAM(VIRTGPU_PARAM_CAPSET_QUERY_FIX),
91 PARAM(VIRTGPU_PARAM_RESOURCE_BLOB),
92 PARAM(VIRTGPU_PARAM_HOST_VISIBLE),
93 PARAM(VIRTGPU_PARAM_CROSS_DEVICE),
94 PARAM(VIRTGPU_PARAM_CONTEXT_INIT),
95 PARAM(VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs)
96 };
97
98 struct virgl_drm_winsys
99 {
100 struct virgl_winsys base;
101 int fd;
102 struct virgl_resource_cache cache;
103 mtx_t mutex;
104
105 int32_t blob_id;
106 struct hash_table *bo_handles;
107 struct hash_table *bo_names;
108 mtx_t bo_handles_mutex;
109 };
110
111 struct virgl_drm_fence {
112 struct pipe_reference reference;
113 bool external;
114 int fd;
115 struct virgl_hw_res *hw_res;
116 };
117
118 struct virgl_drm_cmd_buf {
119 struct virgl_cmd_buf base;
120
121 uint32_t *buf;
122
123 int in_fence_fd;
124
125 unsigned nres;
126 unsigned cres;
127 struct virgl_hw_res **res_bo;
128 struct virgl_winsys *ws;
129 uint32_t *res_hlist;
130 };
131
132 static inline struct virgl_drm_winsys *
133 virgl_drm_winsys(struct virgl_winsys *iws)
134 {
135 return (struct virgl_drm_winsys *)iws;
136 }
137
138 static inline struct virgl_drm_fence *
139 virgl_drm_fence(struct pipe_fence_handle *f)
140 {
141 return (struct virgl_drm_fence *)f;
142 }
143
144 static inline struct virgl_drm_cmd_buf *
145 virgl_drm_cmd_buf(struct virgl_cmd_buf *cbuf)
146 {
147 return (struct virgl_drm_cmd_buf *)cbuf;
148 }
149
150 #endif