virgl: fixup_readback_format --> fixup_formats
[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 #include "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
52 static inline struct virgl_surface *virgl_surface(struct pipe_surface *surf)
53 {
54 return (struct virgl_surface *)surf;
55 }
56
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
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
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_bind_object(struct virgl_context *ctx,
120 uint32_t handle, uint32_t object);
121 int virgl_encode_delete_object(struct virgl_context *ctx,
122 uint32_t handle, uint32_t object);
123
124 int virgl_encoder_set_framebuffer_state(struct virgl_context *ctx,
125 const struct pipe_framebuffer_state *state);
126 int virgl_encoder_set_viewport_states(struct virgl_context *ctx,
127 int start_slot,
128 int num_viewports,
129 const struct pipe_viewport_state *states);
130
131 int virgl_encoder_draw_vbo(struct virgl_context *ctx,
132 const struct pipe_draw_info *info);
133
134
135 int virgl_encoder_create_surface(struct virgl_context *ctx,
136 uint32_t handle,
137 struct virgl_resource *res,
138 const struct pipe_surface *templat);
139
140 int virgl_encoder_flush_frontbuffer(struct virgl_context *ctx,
141 struct virgl_resource *res);
142
143 int virgl_encoder_create_vertex_elements(struct virgl_context *ctx,
144 uint32_t handle,
145 unsigned num_elements,
146 const struct pipe_vertex_element *element);
147
148 int virgl_encoder_set_vertex_buffers(struct virgl_context *ctx,
149 unsigned num_buffers,
150 const struct pipe_vertex_buffer *buffers);
151
152
153 int virgl_encoder_inline_write(struct virgl_context *ctx,
154 struct virgl_resource *res,
155 unsigned level, unsigned usage,
156 const struct pipe_box *box,
157 const void *data, unsigned stride,
158 unsigned layer_stride);
159 int virgl_encode_sampler_state(struct virgl_context *ctx,
160 uint32_t handle,
161 const struct pipe_sampler_state *state);
162 int virgl_encode_sampler_view(struct virgl_context *ctx,
163 uint32_t handle,
164 struct virgl_resource *res,
165 const struct pipe_sampler_view *state);
166
167 int virgl_encode_set_sampler_views(struct virgl_context *ctx,
168 uint32_t shader_type,
169 uint32_t start_slot,
170 uint32_t num_views,
171 struct virgl_sampler_view **views);
172
173 int virgl_encode_bind_sampler_states(struct virgl_context *ctx,
174 uint32_t shader_type,
175 uint32_t start_slot,
176 uint32_t num_handles,
177 uint32_t *handles);
178
179 int virgl_encoder_set_index_buffer(struct virgl_context *ctx,
180 const struct virgl_indexbuf *ib);
181
182 uint32_t virgl_object_assign_handle(void);
183
184 int virgl_encoder_write_constant_buffer(struct virgl_context *ctx,
185 uint32_t shader,
186 uint32_t index,
187 uint32_t size,
188 const void *data);
189
190 int virgl_encoder_set_uniform_buffer(struct virgl_context *ctx,
191 uint32_t shader,
192 uint32_t index,
193 uint32_t offset,
194 uint32_t length,
195 struct virgl_resource *res);
196 int virgl_encode_dsa_state(struct virgl_context *ctx,
197 uint32_t handle,
198 const struct pipe_depth_stencil_alpha_state *dsa_state);
199
200 int virgl_encoder_set_stencil_ref(struct virgl_context *ctx,
201 const struct pipe_stencil_ref *ref);
202
203 int virgl_encoder_set_blend_color(struct virgl_context *ctx,
204 const struct pipe_blend_color *color);
205
206 int virgl_encoder_set_scissor_state(struct virgl_context *ctx,
207 unsigned start_slot,
208 int num_scissors,
209 const struct pipe_scissor_state *ss);
210
211 void virgl_encoder_set_polygon_stipple(struct virgl_context *ctx,
212 const struct pipe_poly_stipple *ps);
213
214 void virgl_encoder_set_sample_mask(struct virgl_context *ctx,
215 unsigned sample_mask);
216
217 void virgl_encoder_set_min_samples(struct virgl_context *ctx,
218 unsigned min_samples);
219
220 void virgl_encoder_set_clip_state(struct virgl_context *ctx,
221 const struct pipe_clip_state *clip);
222
223 int virgl_encode_resource_copy_region(struct virgl_context *ctx,
224 struct virgl_resource *dst_res,
225 unsigned dst_level,
226 unsigned dstx, unsigned dsty, unsigned dstz,
227 struct virgl_resource *src_res,
228 unsigned src_level,
229 const struct pipe_box *src_box);
230
231 int virgl_encode_blit(struct virgl_context *ctx,
232 struct virgl_resource *dst_res,
233 struct virgl_resource *src_res,
234 const struct pipe_blit_info *blit);
235
236 int virgl_encoder_create_query(struct virgl_context *ctx,
237 uint32_t handle,
238 uint query_type,
239 uint query_index,
240 struct virgl_resource *res,
241 uint32_t offset);
242
243 int virgl_encoder_begin_query(struct virgl_context *ctx,
244 uint32_t handle);
245 int virgl_encoder_end_query(struct virgl_context *ctx,
246 uint32_t handle);
247 int virgl_encoder_get_query_result(struct virgl_context *ctx,
248 uint32_t handle, boolean wait);
249
250 int virgl_encoder_render_condition(struct virgl_context *ctx,
251 uint32_t handle, boolean condition,
252 enum pipe_render_cond_flag mode);
253
254 int virgl_encoder_set_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
255 int virgl_encoder_create_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
256 int virgl_encoder_destroy_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
257
258 int virgl_encode_bind_shader(struct virgl_context *ctx,
259 uint32_t handle, uint32_t type);
260
261 int virgl_encode_set_tess_state(struct virgl_context *ctx,
262 const float outer[4],
263 const float inner[2]);
264
265 int virgl_encode_set_shader_buffers(struct virgl_context *ctx,
266 enum pipe_shader_type shader,
267 unsigned start_slot, unsigned count,
268 const struct pipe_shader_buffer *buffers);
269 int virgl_encode_set_shader_images(struct virgl_context *ctx,
270 enum pipe_shader_type shader,
271 unsigned start_slot, unsigned count,
272 const struct pipe_image_view *images);
273 int virgl_encode_set_hw_atomic_buffers(struct virgl_context *ctx,
274 unsigned start_slot, unsigned count,
275 const struct pipe_shader_buffer *buffers);
276 int virgl_encode_memory_barrier(struct virgl_context *ctx,
277 unsigned flags);
278 int virgl_encode_launch_grid(struct virgl_context *ctx,
279 const struct pipe_grid_info *grid_info);
280 int virgl_encode_texture_barrier(struct virgl_context *ctx,
281 unsigned flags);
282
283 int virgl_encode_host_debug_flagstring(struct virgl_context *ctx,
284 const char *envname);
285
286 int virgl_encode_get_query_result_qbo(struct virgl_context *ctx,
287 uint32_t handle,
288 struct virgl_resource *res, boolean wait,
289 uint32_t result_type,
290 uint32_t offset,
291 uint32_t index);
292
293 void virgl_encode_transfer(struct virgl_screen *vs, struct virgl_cmd_buf *buf,
294 struct virgl_transfer *trans, uint32_t direction);
295
296 void virgl_encode_copy_transfer(struct virgl_context *ctx,
297 struct virgl_transfer *trans);
298
299 void virgl_encode_end_transfers(struct virgl_cmd_buf *buf);
300
301 int virgl_encode_tweak(struct virgl_context *ctx, enum vrend_tweak_type tweak, uint32_t value);
302
303 #endif