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