virgl: Support VIRGL_BIND_SHARED
[mesa.git] / src / gallium / drivers / virgl / virgl_encode.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_ENCODE_H
24 #define VIRGL_ENCODE_H
25
26 #include "pipe/p_defines.h"
27 #include "pipe/p_state.h"
28
29 #include "virgl_winsys.h"
30
31 struct tgsi_token;
32
33 struct virgl_context;
34 struct virgl_resource;
35 struct virgl_screen;
36 struct virgl_transfer;
37 struct virgl_sampler_view;
38
39 struct virgl_surface {
40 struct pipe_surface base;
41 uint32_t handle;
42 };
43
44 struct virgl_indexbuf {
45 unsigned offset;
46 unsigned index_size; /**< size of an index, in bytes */
47 struct pipe_resource *buffer; /**< the actual buffer */
48 const void *user_buffer; /**< pointer to a user buffer if buffer == NULL */
49 };
50
51 static inline struct virgl_surface *virgl_surface(struct pipe_surface *surf)
52 {
53 return (struct virgl_surface *)surf;
54 }
55
56 static inline void virgl_encoder_write_dword(struct virgl_cmd_buf *state,
57 uint32_t dword)
58 {
59 state->buf[state->cdw++] = dword;
60 }
61
62 static inline void virgl_encoder_write_qword(struct virgl_cmd_buf *state,
63 uint64_t qword)
64 {
65 memcpy(state->buf + state->cdw, &qword, sizeof(uint64_t));
66 state->cdw += 2;
67 }
68
69 static inline void virgl_encoder_write_block(struct virgl_cmd_buf *state,
70 const uint8_t *ptr, uint32_t len)
71 {
72 int x;
73 memcpy(state->buf + state->cdw, ptr, len);
74 x = (len % 4);
75 if (x) {
76 uint8_t *mp = (uint8_t *)(state->buf + state->cdw);
77 mp += len;
78 memset(mp, 0, x);
79 }
80 state->cdw += (len + 3) / 4;
81 }
82
83 extern int virgl_encode_blend_state(struct virgl_context *ctx,
84 uint32_t handle,
85 const struct pipe_blend_state *blend_state);
86 extern int virgl_encode_rasterizer_state(struct virgl_context *ctx,
87 uint32_t handle,
88 const struct pipe_rasterizer_state *state);
89
90 extern int virgl_encode_shader_state(struct virgl_context *ctx,
91 uint32_t handle,
92 uint32_t type,
93 const struct pipe_stream_output_info *so_info,
94 uint32_t cs_req_local_mem,
95 const struct tgsi_token *tokens);
96
97 int virgl_encode_stream_output_info(struct virgl_context *ctx,
98 uint32_t handle,
99 uint32_t type,
100 const struct pipe_shader_state *shader);
101
102 int virgl_encoder_set_so_targets(struct virgl_context *ctx,
103 unsigned num_targets,
104 struct pipe_stream_output_target **targets,
105 unsigned append_bitmask);
106
107 int virgl_encoder_create_so_target(struct virgl_context *ctx,
108 uint32_t handle,
109 struct virgl_resource *res,
110 unsigned buffer_offset,
111 unsigned buffer_size);
112
113 int virgl_encode_clear(struct virgl_context *ctx,
114 unsigned buffers,
115 const union pipe_color_union *color,
116 double depth, unsigned stencil);
117
118 int virgl_encode_bind_object(struct virgl_context *ctx,
119 uint32_t handle, uint32_t object);
120 int virgl_encode_delete_object(struct virgl_context *ctx,
121 uint32_t handle, uint32_t object);
122
123 int virgl_encoder_set_framebuffer_state(struct virgl_context *ctx,
124 const struct pipe_framebuffer_state *state);
125 int virgl_encoder_set_viewport_states(struct virgl_context *ctx,
126 int start_slot,
127 int num_viewports,
128 const struct pipe_viewport_state *states);
129
130 int virgl_encoder_draw_vbo(struct virgl_context *ctx,
131 const struct pipe_draw_info *info);
132
133
134 int virgl_encoder_create_surface(struct virgl_context *ctx,
135 uint32_t handle,
136 struct virgl_resource *res,
137 const struct pipe_surface *templat);
138
139 int virgl_encoder_flush_frontbuffer(struct virgl_context *ctx,
140 struct virgl_resource *res);
141
142 int virgl_encoder_create_vertex_elements(struct virgl_context *ctx,
143 uint32_t handle,
144 unsigned num_elements,
145 const struct pipe_vertex_element *element);
146
147 int virgl_encoder_set_vertex_buffers(struct virgl_context *ctx,
148 unsigned num_buffers,
149 const struct pipe_vertex_buffer *buffers);
150
151
152 int virgl_encoder_inline_write(struct virgl_context *ctx,
153 struct virgl_resource *res,
154 unsigned level, unsigned usage,
155 const struct pipe_box *box,
156 const void *data, unsigned stride,
157 unsigned layer_stride);
158 int virgl_encode_sampler_state(struct virgl_context *ctx,
159 uint32_t handle,
160 const struct pipe_sampler_state *state);
161 int virgl_encode_sampler_view(struct virgl_context *ctx,
162 uint32_t handle,
163 struct virgl_resource *res,
164 const struct pipe_sampler_view *state);
165
166 int virgl_encode_set_sampler_views(struct virgl_context *ctx,
167 uint32_t shader_type,
168 uint32_t start_slot,
169 uint32_t num_views,
170 struct virgl_sampler_view **views);
171
172 int virgl_encode_bind_sampler_states(struct virgl_context *ctx,
173 uint32_t shader_type,
174 uint32_t start_slot,
175 uint32_t num_handles,
176 uint32_t *handles);
177
178 int virgl_encoder_set_index_buffer(struct virgl_context *ctx,
179 const struct virgl_indexbuf *ib);
180
181 uint32_t virgl_object_assign_handle(void);
182
183 int virgl_encoder_write_constant_buffer(struct virgl_context *ctx,
184 uint32_t shader,
185 uint32_t index,
186 uint32_t size,
187 const void *data);
188
189 int virgl_encoder_set_uniform_buffer(struct virgl_context *ctx,
190 uint32_t shader,
191 uint32_t index,
192 uint32_t offset,
193 uint32_t length,
194 struct virgl_resource *res);
195 int virgl_encode_dsa_state(struct virgl_context *ctx,
196 uint32_t handle,
197 const struct pipe_depth_stencil_alpha_state *dsa_state);
198
199 int virgl_encoder_set_stencil_ref(struct virgl_context *ctx,
200 const struct pipe_stencil_ref *ref);
201
202 int virgl_encoder_set_blend_color(struct virgl_context *ctx,
203 const struct pipe_blend_color *color);
204
205 int virgl_encoder_set_scissor_state(struct virgl_context *ctx,
206 unsigned start_slot,
207 int num_scissors,
208 const struct pipe_scissor_state *ss);
209
210 void virgl_encoder_set_polygon_stipple(struct virgl_context *ctx,
211 const struct pipe_poly_stipple *ps);
212
213 void virgl_encoder_set_sample_mask(struct virgl_context *ctx,
214 unsigned sample_mask);
215
216 void virgl_encoder_set_min_samples(struct virgl_context *ctx,
217 unsigned min_samples);
218
219 void virgl_encoder_set_clip_state(struct virgl_context *ctx,
220 const struct pipe_clip_state *clip);
221
222 int virgl_encode_resource_copy_region(struct virgl_context *ctx,
223 struct virgl_resource *dst_res,
224 unsigned dst_level,
225 unsigned dstx, unsigned dsty, unsigned dstz,
226 struct virgl_resource *src_res,
227 unsigned src_level,
228 const struct pipe_box *src_box);
229
230 int virgl_encode_blit(struct virgl_context *ctx,
231 struct virgl_resource *dst_res,
232 struct virgl_resource *src_res,
233 const struct pipe_blit_info *blit);
234
235 int virgl_encoder_create_query(struct virgl_context *ctx,
236 uint32_t handle,
237 uint query_type,
238 uint query_index,
239 struct virgl_resource *res,
240 uint32_t offset);
241
242 int virgl_encoder_begin_query(struct virgl_context *ctx,
243 uint32_t handle);
244 int virgl_encoder_end_query(struct virgl_context *ctx,
245 uint32_t handle);
246 int virgl_encoder_get_query_result(struct virgl_context *ctx,
247 uint32_t handle, boolean wait);
248
249 int virgl_encoder_render_condition(struct virgl_context *ctx,
250 uint32_t handle, boolean condition,
251 enum pipe_render_cond_flag mode);
252
253 int virgl_encoder_set_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
254 int virgl_encoder_create_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
255 int virgl_encoder_destroy_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
256
257 int virgl_encode_bind_shader(struct virgl_context *ctx,
258 uint32_t handle, uint32_t type);
259
260 int virgl_encode_set_tess_state(struct virgl_context *ctx,
261 const float outer[4],
262 const float inner[2]);
263
264 int virgl_encode_set_shader_buffers(struct virgl_context *ctx,
265 enum pipe_shader_type shader,
266 unsigned start_slot, unsigned count,
267 const struct pipe_shader_buffer *buffers);
268 int virgl_encode_set_shader_images(struct virgl_context *ctx,
269 enum pipe_shader_type shader,
270 unsigned start_slot, unsigned count,
271 const struct pipe_image_view *images);
272 int virgl_encode_set_hw_atomic_buffers(struct virgl_context *ctx,
273 unsigned start_slot, unsigned count,
274 const struct pipe_shader_buffer *buffers);
275 int virgl_encode_memory_barrier(struct virgl_context *ctx,
276 unsigned flags);
277 int virgl_encode_launch_grid(struct virgl_context *ctx,
278 const struct pipe_grid_info *grid_info);
279 int virgl_encode_texture_barrier(struct virgl_context *ctx,
280 unsigned flags);
281
282 int virgl_encode_host_debug_flagstring(struct virgl_context *ctx,
283 const char *envname);
284
285 int virgl_encode_get_query_result_qbo(struct virgl_context *ctx,
286 uint32_t handle,
287 struct virgl_resource *res, boolean wait,
288 uint32_t result_type,
289 uint32_t offset,
290 uint32_t index);
291
292 void virgl_encode_transfer(struct virgl_screen *vs, struct virgl_cmd_buf *buf,
293 struct virgl_transfer *trans, uint32_t direction);
294
295 void virgl_encode_copy_transfer(struct virgl_context *ctx,
296 struct virgl_transfer *trans);
297
298 void virgl_encode_end_transfers(struct virgl_cmd_buf *buf);
299 #endif