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