• 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 
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 
virgl_surface(struct pipe_surface * surf)49 static inline struct virgl_surface *virgl_surface(struct pipe_surface *surf)
50 {
51    return (struct virgl_surface *)surf;
52 }
53 
virgl_encoder_write_dword(struct virgl_cmd_buf * state,uint32_t dword)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 
virgl_encoder_write_qword(struct virgl_cmd_buf * state,uint64_t qword)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 
virgl_encoder_write_block(struct virgl_cmd_buf * state,const uint8_t * ptr,uint32_t len)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                                      const struct tgsi_token *tokens);
94 
95 int virgl_encode_stream_output_info(struct virgl_context *ctx,
96                                    uint32_t handle,
97                                    uint32_t type,
98                                    const struct pipe_shader_state *shader);
99 
100 int virgl_encoder_set_so_targets(struct virgl_context *ctx,
101                                 unsigned num_targets,
102                                 struct pipe_stream_output_target **targets,
103                                 unsigned append_bitmask);
104 
105 int virgl_encoder_create_so_target(struct virgl_context *ctx,
106                                   uint32_t handle,
107                                   struct virgl_resource *res,
108                                   unsigned buffer_offset,
109                                   unsigned buffer_size);
110 
111 int virgl_encode_clear(struct virgl_context *ctx,
112                       unsigned buffers,
113                       const union pipe_color_union *color,
114                       double depth, unsigned stencil);
115 
116 int virgl_encode_bind_object(struct virgl_context *ctx,
117                             uint32_t handle, uint32_t object);
118 int virgl_encode_delete_object(struct virgl_context *ctx,
119                               uint32_t handle, uint32_t object);
120 
121 int virgl_encoder_set_framebuffer_state(struct virgl_context *ctx,
122                                        const struct pipe_framebuffer_state *state);
123 int virgl_encoder_set_viewport_states(struct virgl_context *ctx,
124                                       int start_slot,
125                                       int num_viewports,
126                                       const struct pipe_viewport_state *states);
127 
128 int virgl_encoder_draw_vbo(struct virgl_context *ctx,
129                           const struct pipe_draw_info *info);
130 
131 
132 int virgl_encoder_create_surface(struct virgl_context *ctx,
133                                 uint32_t handle,
134                                 struct virgl_resource *res,
135                                 const struct pipe_surface *templat);
136 
137 int virgl_encoder_flush_frontbuffer(struct virgl_context *ctx,
138                                    struct virgl_resource *res);
139 
140 int virgl_encoder_create_vertex_elements(struct virgl_context *ctx,
141                                         uint32_t handle,
142                                         unsigned num_elements,
143                                         const struct pipe_vertex_element *element);
144 
145 int virgl_encoder_set_vertex_buffers(struct virgl_context *ctx,
146                                     unsigned num_buffers,
147                                     const struct pipe_vertex_buffer *buffers);
148 
149 
150 int virgl_encoder_inline_write(struct virgl_context *ctx,
151                               struct virgl_resource *res,
152                               unsigned level, unsigned usage,
153                               const struct pipe_box *box,
154                               const void *data, unsigned stride,
155                               unsigned layer_stride);
156 int virgl_encode_sampler_state(struct virgl_context *ctx,
157                               uint32_t handle,
158                               const struct pipe_sampler_state *state);
159 int virgl_encode_sampler_view(struct virgl_context *ctx,
160                              uint32_t handle,
161                              struct virgl_resource *res,
162                              const struct pipe_sampler_view *state);
163 
164 int virgl_encode_set_sampler_views(struct virgl_context *ctx,
165                                   uint32_t shader_type,
166                                   uint32_t start_slot,
167                                   uint32_t num_views,
168                                   struct virgl_sampler_view **views);
169 
170 int virgl_encode_bind_sampler_states(struct virgl_context *ctx,
171                                     uint32_t shader_type,
172                                     uint32_t start_slot,
173                                     uint32_t num_handles,
174                                     uint32_t *handles);
175 
176 int virgl_encoder_set_index_buffer(struct virgl_context *ctx,
177                                   const struct virgl_indexbuf *ib);
178 
179 uint32_t virgl_object_assign_handle(void);
180 
181 int virgl_encoder_write_constant_buffer(struct virgl_context *ctx,
182                                        uint32_t shader,
183                                        uint32_t index,
184                                        uint32_t size,
185                                        const void *data);
186 
187 int virgl_encoder_set_uniform_buffer(struct virgl_context *ctx,
188                                      uint32_t shader,
189                                      uint32_t index,
190                                      uint32_t offset,
191                                      uint32_t length,
192                                      struct virgl_resource *res);
193 int virgl_encode_dsa_state(struct virgl_context *ctx,
194                           uint32_t handle,
195                           const struct pipe_depth_stencil_alpha_state *dsa_state);
196 
197 int virgl_encoder_set_stencil_ref(struct virgl_context *ctx,
198                                  const struct pipe_stencil_ref *ref);
199 
200 int virgl_encoder_set_blend_color(struct virgl_context *ctx,
201                                  const struct pipe_blend_color *color);
202 
203 int virgl_encoder_set_scissor_state(struct virgl_context *ctx,
204                                     unsigned start_slot,
205                                     int num_scissors,
206                                     const struct pipe_scissor_state *ss);
207 
208 void virgl_encoder_set_polygon_stipple(struct virgl_context *ctx,
209                                       const struct pipe_poly_stipple *ps);
210 
211 void virgl_encoder_set_sample_mask(struct virgl_context *ctx,
212                                   unsigned sample_mask);
213 
214 void virgl_encoder_set_clip_state(struct virgl_context *ctx,
215                                  const struct pipe_clip_state *clip);
216 
217 int virgl_encode_resource_copy_region(struct virgl_context *ctx,
218                                      struct virgl_resource *dst_res,
219                                      unsigned dst_level,
220                                      unsigned dstx, unsigned dsty, unsigned dstz,
221                                      struct virgl_resource *src_res,
222                                      unsigned src_level,
223                                      const struct pipe_box *src_box);
224 
225 int virgl_encode_blit(struct virgl_context *ctx,
226                      struct virgl_resource *dst_res,
227                      struct virgl_resource *src_res,
228                      const struct pipe_blit_info *blit);
229 
230 int virgl_encoder_create_query(struct virgl_context *ctx,
231                               uint32_t handle,
232                               uint query_type,
233                               uint query_index,
234                               struct virgl_resource *res,
235                               uint32_t offset);
236 
237 int virgl_encoder_begin_query(struct virgl_context *ctx,
238                              uint32_t handle);
239 int virgl_encoder_end_query(struct virgl_context *ctx,
240                            uint32_t handle);
241 int virgl_encoder_get_query_result(struct virgl_context *ctx,
242                                   uint32_t handle, boolean wait);
243 
244 int virgl_encoder_render_condition(struct virgl_context *ctx,
245                                   uint32_t handle, boolean condition,
246                                   enum pipe_render_cond_flag mode);
247 
248 int virgl_encoder_set_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
249 int virgl_encoder_create_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
250 int virgl_encoder_destroy_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
251 
252 int virgl_encode_bind_shader(struct virgl_context *ctx,
253                              uint32_t handle, uint32_t type);
254 #endif
255