1 /**************************************************************************
2 *
3 * Copyright (C) 2015 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 **************************************************************************/
24 #ifndef VIRGL_ENCODE_H
25 #define VIRGL_ENCODE_H
26
27 #include <stdio.h>
28
29 #include "testvirgl.h"
30
31 struct virgl_surface {
32 struct pipe_surface base;
33 uint32_t handle;
34 };
35
virgl_encoder_write_dword(struct virgl_cmd_buf * state,uint32_t dword)36 static inline void virgl_encoder_write_dword(struct virgl_cmd_buf *state,
37 uint32_t dword)
38 {
39 state->buf[state->cdw++] = dword;
40 }
41
virgl_encoder_write_qword(struct virgl_cmd_buf * state,uint64_t qword)42 static inline void virgl_encoder_write_qword(struct virgl_cmd_buf *state,
43 uint64_t qword)
44 {
45 memcpy(state->buf + state->cdw, &qword, sizeof(uint64_t));
46 state->cdw += 2;
47 }
48
virgl_encoder_write_double(struct virgl_cmd_buf * state,double qword)49 static inline void virgl_encoder_write_double(struct virgl_cmd_buf *state,
50 double qword)
51 {
52 memcpy(state->buf + state->cdw, &qword, sizeof(double));
53 state->cdw += 2;
54 }
55
virgl_encoder_write_block(struct virgl_cmd_buf * state,const uint8_t * ptr,uint32_t len)56 static inline void virgl_encoder_write_block(struct virgl_cmd_buf *state,
57 const uint8_t *ptr, uint32_t len)
58 {
59 int x;
60 memcpy(state->buf + state->cdw, ptr, len);
61 x = (len % 4);
62 // fprintf(stderr, "[%d] block %d x is %d\n", state->cdw, len, x);
63 if (x) {
64 uint8_t *mp = (uint8_t *)(state->buf + state->cdw);
65 mp += len;
66 memset(mp, 0, x);
67 }
68 state->cdw += (len + 3) / 4;
69 }
70
71 extern int virgl_encode_blend_state(struct virgl_context *ctx,
72 uint32_t handle,
73 const struct pipe_blend_state *blend_state);
74 extern int virgl_encode_rasterizer_state(struct virgl_context *ctx,
75 uint32_t handle,
76 const struct pipe_rasterizer_state *state);
77
78 extern int virgl_encode_shader_state(struct virgl_context *ctx,
79 uint32_t handle,
80 uint32_t type,
81 const struct pipe_shader_state *shader,
82 const char *shad_str);
83
84 int virgl_encode_stream_output_info(struct virgl_context *ctx,
85 uint32_t handle,
86 uint32_t type,
87 const struct pipe_shader_state *shader);
88
89 int virgl_encoder_set_so_targets(struct virgl_context *ctx,
90 unsigned num_targets,
91 struct pipe_stream_output_target **targets,
92 unsigned append_bitmask);
93
94 int virgl_encoder_create_so_target(struct virgl_context *ctx,
95 uint32_t handle,
96 struct virgl_resource *res,
97 unsigned buffer_offset,
98 unsigned buffer_size);
99
100 int virgl_encode_clear(struct virgl_context *ctx,
101 unsigned buffers,
102 const union pipe_color_union *color,
103 double depth, unsigned stencil);
104
105 int virgl_encode_bind_object(struct virgl_context *ctx,
106 uint32_t handle, uint32_t object);
107 int virgl_encode_delete_object(struct virgl_context *ctx,
108 uint32_t handle, uint32_t object);
109
110 int virgl_encoder_set_framebuffer_state(struct virgl_context *ctx,
111 const struct pipe_framebuffer_state *state);
112 int virgl_encoder_set_viewport_states(struct virgl_context *ctx,
113 int start_slot,
114 int num_viewports,
115 const struct pipe_viewport_state *states);
116
117 int virgl_encoder_draw_vbo(struct virgl_context *ctx,
118 const struct pipe_draw_info *info);
119
120
121 int virgl_encoder_create_surface(struct virgl_context *ctx,
122 uint32_t handle,
123 struct virgl_resource *res,
124 const struct pipe_surface *templat);
125
126 int virgl_encoder_flush_frontbuffer(struct virgl_context *ctx,
127 struct virgl_resource *res);
128
129 int virgl_encoder_create_vertex_elements(struct virgl_context *ctx,
130 uint32_t handle,
131 unsigned num_elements,
132 const struct pipe_vertex_element *element);
133
134 int virgl_encoder_set_vertex_buffers(struct virgl_context *ctx,
135 unsigned num_buffers,
136 const struct pipe_vertex_buffer *buffers);
137
138
139 int virgl_encoder_inline_write(struct virgl_context *ctx,
140 struct virgl_resource *res,
141 unsigned level, unsigned usage,
142 const struct pipe_box *box,
143 const void *data, unsigned stride,
144 unsigned layer_stride);
145
146 int virgl_encoder_transfer(struct virgl_context *ctx,
147 struct virgl_resource *res,
148 unsigned level, unsigned usage,
149 const struct pipe_box *box,
150 unsigned offset, unsigned direction);
151
152 int virgl_encoder_transfer_with_stride(struct virgl_context *ctx,
153 struct virgl_resource *res,
154 unsigned level, unsigned usage,
155 const struct pipe_box *box,
156 unsigned offset, unsigned direction,
157 unsigned stride, unsigned layer_stride);
158
159 int virgl_encoder_copy_transfer(struct virgl_context *ctx,
160 struct virgl_resource *res,
161 unsigned level, unsigned usage,
162 const struct pipe_box *box,
163 struct virgl_resource *src_res,
164 unsigned src_offset,
165 unsigned synchronized);
166
167 int virgl_encode_sampler_state(struct virgl_context *ctx,
168 uint32_t handle,
169 const struct pipe_sampler_state *state);
170 int virgl_encode_sampler_view(struct virgl_context *ctx,
171 uint32_t handle,
172 struct virgl_resource *res,
173 const struct pipe_sampler_view *state);
174
175 int virgl_encode_set_sampler_views(struct virgl_context *ctx,
176 uint32_t shader_type,
177 uint32_t start_slot,
178 uint32_t num_views,
179 struct virgl_sampler_view **views);
180
181 int virgl_encode_bind_sampler_states(struct virgl_context *ctx,
182 uint32_t shader_type,
183 uint32_t start_slot,
184 uint32_t num_handles,
185 uint32_t *handles);
186
187 int virgl_encoder_set_index_buffer(struct virgl_context *ctx,
188 const struct pipe_index_buffer *ib);
189
190 uint32_t virgl_object_assign_handle(void);
191
192 int virgl_encoder_write_constant_buffer(struct virgl_context *ctx,
193 uint32_t shader,
194 uint32_t index,
195 uint32_t size,
196 const void *data);
197
198 int virgl_encoder_set_uniform_buffer(struct virgl_context *ctx,
199 uint32_t shader,
200 uint32_t index,
201 uint32_t offset,
202 uint32_t length,
203 struct virgl_resource *res);
204 int virgl_encode_dsa_state(struct virgl_context *ctx,
205 uint32_t handle,
206 const struct pipe_depth_stencil_alpha_state *dsa_state);
207
208 int virgl_encoder_set_stencil_ref(struct virgl_context *ctx,
209 const struct pipe_stencil_ref *ref);
210
211 int virgl_encoder_set_blend_color(struct virgl_context *ctx,
212 const struct pipe_blend_color *color);
213
214 int virgl_encoder_set_scissor_state(struct virgl_context *ctx,
215 unsigned start_slot,
216 int num_scissors,
217 const struct pipe_scissor_state *ss);
218
219 void virgl_encoder_set_polygon_stipple(struct virgl_context *ctx,
220 const struct pipe_poly_stipple *ps);
221
222 void virgl_encoder_set_sample_mask(struct virgl_context *ctx,
223 unsigned sample_mask);
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 struct virgl_resource *res,
245 uint32_t offset);
246
247 int virgl_encoder_begin_query(struct virgl_context *ctx,
248 uint32_t handle);
249 int virgl_encoder_end_query(struct virgl_context *ctx,
250 uint32_t handle);
251 int virgl_encoder_get_query_result(struct virgl_context *ctx,
252 uint32_t handle, boolean wait);
253
254 int virgl_encoder_render_condition(struct virgl_context *ctx,
255 uint32_t handle, boolean condition,
256 uint mode);
257
258 int virgl_encoder_set_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
259 int virgl_encoder_create_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
260 int virgl_encoder_destroy_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
261 int virgl_encode_bind_shader(struct virgl_context *ctx,
262 uint32_t handle, uint32_t type);
263 #endif
264