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