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