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 int virgl_encode_sampler_state(struct virgl_context *ctx,
146 uint32_t handle,
147 const struct pipe_sampler_state *state);
148 int virgl_encode_sampler_view(struct virgl_context *ctx,
149 uint32_t handle,
150 struct virgl_resource *res,
151 const struct pipe_sampler_view *state);
152
153 int virgl_encode_set_sampler_views(struct virgl_context *ctx,
154 uint32_t shader_type,
155 uint32_t start_slot,
156 uint32_t num_views,
157 struct virgl_sampler_view **views);
158
159 int virgl_encode_bind_sampler_states(struct virgl_context *ctx,
160 uint32_t shader_type,
161 uint32_t start_slot,
162 uint32_t num_handles,
163 uint32_t *handles);
164
165 int virgl_encoder_set_index_buffer(struct virgl_context *ctx,
166 const struct pipe_index_buffer *ib);
167
168 uint32_t virgl_object_assign_handle(void);
169
170 int virgl_encoder_write_constant_buffer(struct virgl_context *ctx,
171 uint32_t shader,
172 uint32_t index,
173 uint32_t size,
174 const void *data);
175
176 int virgl_encoder_set_uniform_buffer(struct virgl_context *ctx,
177 uint32_t shader,
178 uint32_t index,
179 uint32_t offset,
180 uint32_t length,
181 struct virgl_resource *res);
182 int virgl_encode_dsa_state(struct virgl_context *ctx,
183 uint32_t handle,
184 const struct pipe_depth_stencil_alpha_state *dsa_state);
185
186 int virgl_encoder_set_stencil_ref(struct virgl_context *ctx,
187 const struct pipe_stencil_ref *ref);
188
189 int virgl_encoder_set_blend_color(struct virgl_context *ctx,
190 const struct pipe_blend_color *color);
191
192 int virgl_encoder_set_scissor_state(struct virgl_context *ctx,
193 unsigned start_slot,
194 int num_scissors,
195 const struct pipe_scissor_state *ss);
196
197 void virgl_encoder_set_polygon_stipple(struct virgl_context *ctx,
198 const struct pipe_poly_stipple *ps);
199
200 void virgl_encoder_set_sample_mask(struct virgl_context *ctx,
201 unsigned sample_mask);
202
203 void virgl_encoder_set_clip_state(struct virgl_context *ctx,
204 const struct pipe_clip_state *clip);
205
206 int virgl_encode_resource_copy_region(struct virgl_context *ctx,
207 struct virgl_resource *dst_res,
208 unsigned dst_level,
209 unsigned dstx, unsigned dsty, unsigned dstz,
210 struct virgl_resource *src_res,
211 unsigned src_level,
212 const struct pipe_box *src_box);
213
214 int virgl_encode_blit(struct virgl_context *ctx,
215 struct virgl_resource *dst_res,
216 struct virgl_resource *src_res,
217 const struct pipe_blit_info *blit);
218
219 int virgl_encoder_create_query(struct virgl_context *ctx,
220 uint32_t handle,
221 uint query_type,
222 struct virgl_resource *res,
223 uint32_t offset);
224
225 int virgl_encoder_begin_query(struct virgl_context *ctx,
226 uint32_t handle);
227 int virgl_encoder_end_query(struct virgl_context *ctx,
228 uint32_t handle);
229 int virgl_encoder_get_query_result(struct virgl_context *ctx,
230 uint32_t handle, boolean wait);
231
232 int virgl_encoder_render_condition(struct virgl_context *ctx,
233 uint32_t handle, boolean condition,
234 uint mode);
235
236 int virgl_encoder_set_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
237 int virgl_encoder_create_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
238 int virgl_encoder_destroy_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
239 int virgl_encode_bind_shader(struct virgl_context *ctx,
240 uint32_t handle, uint32_t type);
241 #endif
242