virgl: add driver for virtio-gpu 3D (v2)
[mesa.git] / src / gallium / drivers / virgl / virgl_encode.h
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 "virgl_context.h"
27 struct virgl_surface {
28 struct pipe_surface base;
29 uint32_t handle;
30 };
31
32 static inline void virgl_encoder_write_dword(struct virgl_cmd_buf *state,
33 uint32_t dword)
34 {
35 state->buf[state->cdw++] = dword;
36 }
37
38 static inline void virgl_encoder_write_qword(struct virgl_cmd_buf *state,
39 uint64_t qword)
40 {
41 memcpy(state->buf + state->cdw, &qword, sizeof(uint64_t));
42 state->cdw += 2;
43 }
44
45 static inline void virgl_encoder_write_block(struct virgl_cmd_buf *state,
46 const uint8_t *ptr, uint32_t len)
47 {
48 int x;
49 memcpy(state->buf + state->cdw, ptr, len);
50 x = (len % 4);
51 // fprintf(stderr, "[%d] block %d x is %d\n", state->cdw, len, x);
52 if (x) {
53 uint8_t *mp = (uint8_t *)(state->buf + state->cdw);
54 mp += len;
55 memset(mp, 0, x);
56 }
57 state->cdw += (len + 3) / 4;
58 }
59
60 extern int virgl_encode_blend_state(struct virgl_context *ctx,
61 uint32_t handle,
62 const struct pipe_blend_state *blend_state);
63 extern int virgl_encode_rasterizer_state(struct virgl_context *ctx,
64 uint32_t handle,
65 const struct pipe_rasterizer_state *state);
66
67 extern int virgl_encode_shader_state(struct virgl_context *ctx,
68 uint32_t handle,
69 uint32_t type,
70 const struct pipe_stream_output_info *so_info,
71 const struct tgsi_token *tokens);
72
73 int virgl_encode_stream_output_info(struct virgl_context *ctx,
74 uint32_t handle,
75 uint32_t type,
76 const struct pipe_shader_state *shader);
77
78 int virgl_encoder_set_so_targets(struct virgl_context *ctx,
79 unsigned num_targets,
80 struct pipe_stream_output_target **targets,
81 unsigned append_bitmask);
82
83 int virgl_encoder_create_so_target(struct virgl_context *ctx,
84 uint32_t handle,
85 struct virgl_resource *res,
86 unsigned buffer_offset,
87 unsigned buffer_size);
88
89 int virgl_encode_clear(struct virgl_context *ctx,
90 unsigned buffers,
91 const union pipe_color_union *color,
92 double depth, unsigned stencil);
93
94 int virgl_encode_bind_object(struct virgl_context *ctx,
95 uint32_t handle, uint32_t object);
96 int virgl_encode_delete_object(struct virgl_context *ctx,
97 uint32_t handle, uint32_t object);
98
99 int virgl_encoder_set_framebuffer_state(struct virgl_context *ctx,
100 const struct pipe_framebuffer_state *state);
101 int virgl_encoder_set_viewport_states(struct virgl_context *ctx,
102 int start_slot,
103 int num_viewports,
104 const struct pipe_viewport_state *states);
105
106 int virgl_encoder_draw_vbo(struct virgl_context *ctx,
107 const struct pipe_draw_info *info);
108
109
110 int virgl_encoder_create_surface(struct virgl_context *ctx,
111 uint32_t handle,
112 struct virgl_resource *res,
113 const struct pipe_surface *templat);
114
115 int virgl_encoder_flush_frontbuffer(struct virgl_context *ctx,
116 struct virgl_resource *res);
117
118 int virgl_encoder_create_vertex_elements(struct virgl_context *ctx,
119 uint32_t handle,
120 unsigned num_elements,
121 const struct pipe_vertex_element *element);
122
123 int virgl_encoder_set_vertex_buffers(struct virgl_context *ctx,
124 unsigned num_buffers,
125 const struct pipe_vertex_buffer *buffers);
126
127
128 int virgl_encoder_inline_write(struct virgl_context *ctx,
129 struct virgl_resource *res,
130 unsigned level, unsigned usage,
131 const struct pipe_box *box,
132 const void *data, unsigned stride,
133 unsigned layer_stride);
134 int virgl_encode_sampler_state(struct virgl_context *ctx,
135 uint32_t handle,
136 const struct pipe_sampler_state *state);
137 int virgl_encode_sampler_view(struct virgl_context *ctx,
138 uint32_t handle,
139 struct virgl_resource *res,
140 const struct pipe_sampler_view *state);
141
142 int virgl_encode_set_sampler_views(struct virgl_context *ctx,
143 uint32_t shader_type,
144 uint32_t start_slot,
145 uint32_t num_views,
146 struct virgl_sampler_view **views);
147
148 int virgl_encode_bind_sampler_states(struct virgl_context *ctx,
149 uint32_t shader_type,
150 uint32_t start_slot,
151 uint32_t num_handles,
152 uint32_t *handles);
153
154 int virgl_encoder_set_index_buffer(struct virgl_context *ctx,
155 const struct pipe_index_buffer *ib);
156
157 uint32_t virgl_object_assign_handle(void);
158
159 int virgl_encoder_write_constant_buffer(struct virgl_context *ctx,
160 uint32_t shader,
161 uint32_t index,
162 uint32_t size,
163 const void *data);
164
165 int virgl_encoder_set_uniform_buffer(struct virgl_context *ctx,
166 uint32_t shader,
167 uint32_t index,
168 uint32_t offset,
169 uint32_t length,
170 struct virgl_resource *res);
171 int virgl_encode_dsa_state(struct virgl_context *ctx,
172 uint32_t handle,
173 const struct pipe_depth_stencil_alpha_state *dsa_state);
174
175 int virgl_encoder_set_stencil_ref(struct virgl_context *ctx,
176 const struct pipe_stencil_ref *ref);
177
178 int virgl_encoder_set_blend_color(struct virgl_context *ctx,
179 const struct pipe_blend_color *color);
180
181 int virgl_encoder_set_scissor_state(struct virgl_context *ctx,
182 unsigned start_slot,
183 int num_scissors,
184 const struct pipe_scissor_state *ss);
185
186 void virgl_encoder_set_polygon_stipple(struct virgl_context *ctx,
187 const struct pipe_poly_stipple *ps);
188
189 void virgl_encoder_set_sample_mask(struct virgl_context *ctx,
190 unsigned sample_mask);
191
192 void virgl_encoder_set_clip_state(struct virgl_context *ctx,
193 const struct pipe_clip_state *clip);
194
195 int virgl_encode_resource_copy_region(struct virgl_context *ctx,
196 struct virgl_resource *dst_res,
197 unsigned dst_level,
198 unsigned dstx, unsigned dsty, unsigned dstz,
199 struct virgl_resource *src_res,
200 unsigned src_level,
201 const struct pipe_box *src_box);
202
203 int virgl_encode_blit(struct virgl_context *ctx,
204 struct virgl_resource *dst_res,
205 struct virgl_resource *src_res,
206 const struct pipe_blit_info *blit);
207
208 int virgl_encoder_create_query(struct virgl_context *ctx,
209 uint32_t handle,
210 uint query_type,
211 uint query_index,
212 struct virgl_resource *res,
213 uint32_t offset);
214
215 int virgl_encoder_begin_query(struct virgl_context *ctx,
216 uint32_t handle);
217 int virgl_encoder_end_query(struct virgl_context *ctx,
218 uint32_t handle);
219 int virgl_encoder_get_query_result(struct virgl_context *ctx,
220 uint32_t handle, boolean wait);
221
222 int virgl_encoder_render_condition(struct virgl_context *ctx,
223 uint32_t handle, boolean condition,
224 uint mode);
225
226 int virgl_encoder_set_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
227 int virgl_encoder_create_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
228 int virgl_encoder_destroy_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
229
230 int virgl_encode_bind_shader(struct virgl_context *ctx,
231 uint32_t handle, uint32_t type);
232 #endif