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