2 * Copyright 2014, 2015 Red Hat.
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:
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
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.
23 #ifndef VIRGL_ENCODE_H
24 #define VIRGL_ENCODE_H
26 #include "pipe/p_defines.h"
27 #include "pipe/p_state.h"
29 #include "virgl_winsys.h"
30 #include "virgl_protocol.h"
35 struct virgl_resource
;
37 struct virgl_transfer
;
38 struct virgl_sampler_view
;
40 struct virgl_surface
{
41 struct pipe_surface base
;
45 struct virgl_indexbuf
{
47 unsigned index_size
; /**< size of an index, in bytes */
48 struct pipe_resource
*buffer
; /**< the actual buffer */
49 const void *user_buffer
; /**< pointer to a user buffer if buffer == NULL */
52 static inline struct virgl_surface
*virgl_surface(struct pipe_surface
*surf
)
54 return (struct virgl_surface
*)surf
;
57 static inline void virgl_encoder_write_dword(struct virgl_cmd_buf
*state
,
60 state
->buf
[state
->cdw
++] = dword
;
63 static inline void virgl_encoder_write_qword(struct virgl_cmd_buf
*state
,
66 memcpy(state
->buf
+ state
->cdw
, &qword
, sizeof(uint64_t));
70 static inline void virgl_encoder_write_block(struct virgl_cmd_buf
*state
,
71 const uint8_t *ptr
, uint32_t len
)
74 memcpy(state
->buf
+ state
->cdw
, ptr
, len
);
77 uint8_t *mp
= (uint8_t *)(state
->buf
+ state
->cdw
);
81 state
->cdw
+= (len
+ 3) / 4;
84 extern int virgl_encode_blend_state(struct virgl_context
*ctx
,
86 const struct pipe_blend_state
*blend_state
);
87 extern int virgl_encode_rasterizer_state(struct virgl_context
*ctx
,
89 const struct pipe_rasterizer_state
*state
);
91 extern int virgl_encode_shader_state(struct virgl_context
*ctx
,
94 const struct pipe_stream_output_info
*so_info
,
95 uint32_t cs_req_local_mem
,
96 const struct tgsi_token
*tokens
);
98 int virgl_encode_stream_output_info(struct virgl_context
*ctx
,
101 const struct pipe_shader_state
*shader
);
103 int virgl_encoder_set_so_targets(struct virgl_context
*ctx
,
104 unsigned num_targets
,
105 struct pipe_stream_output_target
**targets
,
106 unsigned append_bitmask
);
108 int virgl_encoder_create_so_target(struct virgl_context
*ctx
,
110 struct virgl_resource
*res
,
111 unsigned buffer_offset
,
112 unsigned buffer_size
);
114 int virgl_encode_clear(struct virgl_context
*ctx
,
116 const union pipe_color_union
*color
,
117 double depth
, unsigned stencil
);
119 int virgl_encode_bind_object(struct virgl_context
*ctx
,
120 uint32_t handle
, uint32_t object
);
121 int virgl_encode_delete_object(struct virgl_context
*ctx
,
122 uint32_t handle
, uint32_t object
);
124 int virgl_encoder_set_framebuffer_state(struct virgl_context
*ctx
,
125 const struct pipe_framebuffer_state
*state
);
126 int virgl_encoder_set_viewport_states(struct virgl_context
*ctx
,
129 const struct pipe_viewport_state
*states
);
131 int virgl_encoder_draw_vbo(struct virgl_context
*ctx
,
132 const struct pipe_draw_info
*info
);
135 int virgl_encoder_create_surface(struct virgl_context
*ctx
,
137 struct virgl_resource
*res
,
138 const struct pipe_surface
*templat
);
140 int virgl_encoder_flush_frontbuffer(struct virgl_context
*ctx
,
141 struct virgl_resource
*res
);
143 int virgl_encoder_create_vertex_elements(struct virgl_context
*ctx
,
145 unsigned num_elements
,
146 const struct pipe_vertex_element
*element
);
148 int virgl_encoder_set_vertex_buffers(struct virgl_context
*ctx
,
149 unsigned num_buffers
,
150 const struct pipe_vertex_buffer
*buffers
);
153 int virgl_encoder_inline_write(struct virgl_context
*ctx
,
154 struct virgl_resource
*res
,
155 unsigned level
, unsigned usage
,
156 const struct pipe_box
*box
,
157 const void *data
, unsigned stride
,
158 unsigned layer_stride
);
159 int virgl_encode_sampler_state(struct virgl_context
*ctx
,
161 const struct pipe_sampler_state
*state
);
162 int virgl_encode_sampler_view(struct virgl_context
*ctx
,
164 struct virgl_resource
*res
,
165 const struct pipe_sampler_view
*state
);
167 int virgl_encode_set_sampler_views(struct virgl_context
*ctx
,
168 uint32_t shader_type
,
171 struct virgl_sampler_view
**views
);
173 int virgl_encode_bind_sampler_states(struct virgl_context
*ctx
,
174 uint32_t shader_type
,
176 uint32_t num_handles
,
179 int virgl_encoder_set_index_buffer(struct virgl_context
*ctx
,
180 const struct virgl_indexbuf
*ib
);
182 uint32_t virgl_object_assign_handle(void);
184 int virgl_encoder_write_constant_buffer(struct virgl_context
*ctx
,
190 int virgl_encoder_set_uniform_buffer(struct virgl_context
*ctx
,
195 struct virgl_resource
*res
);
196 int virgl_encode_dsa_state(struct virgl_context
*ctx
,
198 const struct pipe_depth_stencil_alpha_state
*dsa_state
);
200 int virgl_encoder_set_stencil_ref(struct virgl_context
*ctx
,
201 const struct pipe_stencil_ref
*ref
);
203 int virgl_encoder_set_blend_color(struct virgl_context
*ctx
,
204 const struct pipe_blend_color
*color
);
206 int virgl_encoder_set_scissor_state(struct virgl_context
*ctx
,
209 const struct pipe_scissor_state
*ss
);
211 void virgl_encoder_set_polygon_stipple(struct virgl_context
*ctx
,
212 const struct pipe_poly_stipple
*ps
);
214 void virgl_encoder_set_sample_mask(struct virgl_context
*ctx
,
215 unsigned sample_mask
);
217 void virgl_encoder_set_min_samples(struct virgl_context
*ctx
,
218 unsigned min_samples
);
220 void virgl_encoder_set_clip_state(struct virgl_context
*ctx
,
221 const struct pipe_clip_state
*clip
);
223 int virgl_encode_resource_copy_region(struct virgl_context
*ctx
,
224 struct virgl_resource
*dst_res
,
226 unsigned dstx
, unsigned dsty
, unsigned dstz
,
227 struct virgl_resource
*src_res
,
229 const struct pipe_box
*src_box
);
231 int virgl_encode_blit(struct virgl_context
*ctx
,
232 struct virgl_resource
*dst_res
,
233 struct virgl_resource
*src_res
,
234 const struct pipe_blit_info
*blit
);
236 int virgl_encoder_create_query(struct virgl_context
*ctx
,
240 struct virgl_resource
*res
,
243 int virgl_encoder_begin_query(struct virgl_context
*ctx
,
245 int virgl_encoder_end_query(struct virgl_context
*ctx
,
247 int virgl_encoder_get_query_result(struct virgl_context
*ctx
,
248 uint32_t handle
, boolean wait
);
250 int virgl_encoder_render_condition(struct virgl_context
*ctx
,
251 uint32_t handle
, boolean condition
,
252 enum pipe_render_cond_flag mode
);
254 int virgl_encoder_set_sub_ctx(struct virgl_context
*ctx
, uint32_t sub_ctx_id
);
255 int virgl_encoder_create_sub_ctx(struct virgl_context
*ctx
, uint32_t sub_ctx_id
);
256 int virgl_encoder_destroy_sub_ctx(struct virgl_context
*ctx
, uint32_t sub_ctx_id
);
258 int virgl_encode_bind_shader(struct virgl_context
*ctx
,
259 uint32_t handle
, uint32_t type
);
261 int virgl_encode_set_tess_state(struct virgl_context
*ctx
,
262 const float outer
[4],
263 const float inner
[2]);
265 int virgl_encode_set_shader_buffers(struct virgl_context
*ctx
,
266 enum pipe_shader_type shader
,
267 unsigned start_slot
, unsigned count
,
268 const struct pipe_shader_buffer
*buffers
);
269 int virgl_encode_set_shader_images(struct virgl_context
*ctx
,
270 enum pipe_shader_type shader
,
271 unsigned start_slot
, unsigned count
,
272 const struct pipe_image_view
*images
);
273 int virgl_encode_set_hw_atomic_buffers(struct virgl_context
*ctx
,
274 unsigned start_slot
, unsigned count
,
275 const struct pipe_shader_buffer
*buffers
);
276 int virgl_encode_memory_barrier(struct virgl_context
*ctx
,
278 int virgl_encode_launch_grid(struct virgl_context
*ctx
,
279 const struct pipe_grid_info
*grid_info
);
280 int virgl_encode_texture_barrier(struct virgl_context
*ctx
,
283 int virgl_encode_host_debug_flagstring(struct virgl_context
*ctx
,
284 const char *envname
);
286 int virgl_encode_get_query_result_qbo(struct virgl_context
*ctx
,
288 struct virgl_resource
*res
, boolean wait
,
289 uint32_t result_type
,
293 void virgl_encode_transfer(struct virgl_screen
*vs
, struct virgl_cmd_buf
*buf
,
294 struct virgl_transfer
*trans
, uint32_t direction
);
296 void virgl_encode_copy_transfer(struct virgl_context
*ctx
,
297 struct virgl_transfer
*trans
);
299 void virgl_encode_end_transfers(struct virgl_cmd_buf
*buf
);
301 int virgl_encode_tweak(struct virgl_context
*ctx
, enum vrend_tweak_type tweak
, uint32_t value
);