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"
34 struct virgl_resource
;
36 struct virgl_transfer
;
37 struct virgl_sampler_view
;
39 struct virgl_surface
{
40 struct pipe_surface base
;
44 struct virgl_indexbuf
{
46 unsigned index_size
; /**< size of an index, in bytes */
47 struct pipe_resource
*buffer
; /**< the actual buffer */
48 const void *user_buffer
; /**< pointer to a user buffer if buffer == NULL */
51 static inline struct virgl_surface
*virgl_surface(struct pipe_surface
*surf
)
53 return (struct virgl_surface
*)surf
;
56 static inline void virgl_encoder_write_dword(struct virgl_cmd_buf
*state
,
59 state
->buf
[state
->cdw
++] = dword
;
62 static inline void virgl_encoder_write_qword(struct virgl_cmd_buf
*state
,
65 memcpy(state
->buf
+ state
->cdw
, &qword
, sizeof(uint64_t));
69 static inline void virgl_encoder_write_block(struct virgl_cmd_buf
*state
,
70 const uint8_t *ptr
, uint32_t len
)
73 memcpy(state
->buf
+ state
->cdw
, ptr
, len
);
76 uint8_t *mp
= (uint8_t *)(state
->buf
+ state
->cdw
);
80 state
->cdw
+= (len
+ 3) / 4;
83 extern int virgl_encode_blend_state(struct virgl_context
*ctx
,
85 const struct pipe_blend_state
*blend_state
);
86 extern int virgl_encode_rasterizer_state(struct virgl_context
*ctx
,
88 const struct pipe_rasterizer_state
*state
);
90 extern int virgl_encode_shader_state(struct virgl_context
*ctx
,
93 const struct pipe_stream_output_info
*so_info
,
94 uint32_t cs_req_local_mem
,
95 const struct tgsi_token
*tokens
);
97 int virgl_encode_stream_output_info(struct virgl_context
*ctx
,
100 const struct pipe_shader_state
*shader
);
102 int virgl_encoder_set_so_targets(struct virgl_context
*ctx
,
103 unsigned num_targets
,
104 struct pipe_stream_output_target
**targets
,
105 unsigned append_bitmask
);
107 int virgl_encoder_create_so_target(struct virgl_context
*ctx
,
109 struct virgl_resource
*res
,
110 unsigned buffer_offset
,
111 unsigned buffer_size
);
113 int virgl_encode_clear(struct virgl_context
*ctx
,
115 const union pipe_color_union
*color
,
116 double depth
, unsigned stencil
);
118 int virgl_encode_bind_object(struct virgl_context
*ctx
,
119 uint32_t handle
, uint32_t object
);
120 int virgl_encode_delete_object(struct virgl_context
*ctx
,
121 uint32_t handle
, uint32_t object
);
123 int virgl_encoder_set_framebuffer_state(struct virgl_context
*ctx
,
124 const struct pipe_framebuffer_state
*state
);
125 int virgl_encoder_set_viewport_states(struct virgl_context
*ctx
,
128 const struct pipe_viewport_state
*states
);
130 int virgl_encoder_draw_vbo(struct virgl_context
*ctx
,
131 const struct pipe_draw_info
*info
);
134 int virgl_encoder_create_surface(struct virgl_context
*ctx
,
136 struct virgl_resource
*res
,
137 const struct pipe_surface
*templat
);
139 int virgl_encoder_flush_frontbuffer(struct virgl_context
*ctx
,
140 struct virgl_resource
*res
);
142 int virgl_encoder_create_vertex_elements(struct virgl_context
*ctx
,
144 unsigned num_elements
,
145 const struct pipe_vertex_element
*element
);
147 int virgl_encoder_set_vertex_buffers(struct virgl_context
*ctx
,
148 unsigned num_buffers
,
149 const struct pipe_vertex_buffer
*buffers
);
152 int virgl_encoder_inline_write(struct virgl_context
*ctx
,
153 struct virgl_resource
*res
,
154 unsigned level
, unsigned usage
,
155 const struct pipe_box
*box
,
156 const void *data
, unsigned stride
,
157 unsigned layer_stride
);
158 int virgl_encode_sampler_state(struct virgl_context
*ctx
,
160 const struct pipe_sampler_state
*state
);
161 int virgl_encode_sampler_view(struct virgl_context
*ctx
,
163 struct virgl_resource
*res
,
164 const struct pipe_sampler_view
*state
);
166 int virgl_encode_set_sampler_views(struct virgl_context
*ctx
,
167 uint32_t shader_type
,
170 struct virgl_sampler_view
**views
);
172 int virgl_encode_bind_sampler_states(struct virgl_context
*ctx
,
173 uint32_t shader_type
,
175 uint32_t num_handles
,
178 int virgl_encoder_set_index_buffer(struct virgl_context
*ctx
,
179 const struct virgl_indexbuf
*ib
);
181 uint32_t virgl_object_assign_handle(void);
183 int virgl_encoder_write_constant_buffer(struct virgl_context
*ctx
,
189 int virgl_encoder_set_uniform_buffer(struct virgl_context
*ctx
,
194 struct virgl_resource
*res
);
195 int virgl_encode_dsa_state(struct virgl_context
*ctx
,
197 const struct pipe_depth_stencil_alpha_state
*dsa_state
);
199 int virgl_encoder_set_stencil_ref(struct virgl_context
*ctx
,
200 const struct pipe_stencil_ref
*ref
);
202 int virgl_encoder_set_blend_color(struct virgl_context
*ctx
,
203 const struct pipe_blend_color
*color
);
205 int virgl_encoder_set_scissor_state(struct virgl_context
*ctx
,
208 const struct pipe_scissor_state
*ss
);
210 void virgl_encoder_set_polygon_stipple(struct virgl_context
*ctx
,
211 const struct pipe_poly_stipple
*ps
);
213 void virgl_encoder_set_sample_mask(struct virgl_context
*ctx
,
214 unsigned sample_mask
);
216 void virgl_encoder_set_min_samples(struct virgl_context
*ctx
,
217 unsigned min_samples
);
219 void virgl_encoder_set_clip_state(struct virgl_context
*ctx
,
220 const struct pipe_clip_state
*clip
);
222 int virgl_encode_resource_copy_region(struct virgl_context
*ctx
,
223 struct virgl_resource
*dst_res
,
225 unsigned dstx
, unsigned dsty
, unsigned dstz
,
226 struct virgl_resource
*src_res
,
228 const struct pipe_box
*src_box
);
230 int virgl_encode_blit(struct virgl_context
*ctx
,
231 struct virgl_resource
*dst_res
,
232 struct virgl_resource
*src_res
,
233 const struct pipe_blit_info
*blit
);
235 int virgl_encoder_create_query(struct virgl_context
*ctx
,
239 struct virgl_resource
*res
,
242 int virgl_encoder_begin_query(struct virgl_context
*ctx
,
244 int virgl_encoder_end_query(struct virgl_context
*ctx
,
246 int virgl_encoder_get_query_result(struct virgl_context
*ctx
,
247 uint32_t handle
, boolean wait
);
249 int virgl_encoder_render_condition(struct virgl_context
*ctx
,
250 uint32_t handle
, boolean condition
,
251 enum pipe_render_cond_flag mode
);
253 int virgl_encoder_set_sub_ctx(struct virgl_context
*ctx
, uint32_t sub_ctx_id
);
254 int virgl_encoder_create_sub_ctx(struct virgl_context
*ctx
, uint32_t sub_ctx_id
);
255 int virgl_encoder_destroy_sub_ctx(struct virgl_context
*ctx
, uint32_t sub_ctx_id
);
257 int virgl_encode_bind_shader(struct virgl_context
*ctx
,
258 uint32_t handle
, uint32_t type
);
260 int virgl_encode_set_tess_state(struct virgl_context
*ctx
,
261 const float outer
[4],
262 const float inner
[2]);
264 int virgl_encode_set_shader_buffers(struct virgl_context
*ctx
,
265 enum pipe_shader_type shader
,
266 unsigned start_slot
, unsigned count
,
267 const struct pipe_shader_buffer
*buffers
);
268 int virgl_encode_set_shader_images(struct virgl_context
*ctx
,
269 enum pipe_shader_type shader
,
270 unsigned start_slot
, unsigned count
,
271 const struct pipe_image_view
*images
);
272 int virgl_encode_set_hw_atomic_buffers(struct virgl_context
*ctx
,
273 unsigned start_slot
, unsigned count
,
274 const struct pipe_shader_buffer
*buffers
);
275 int virgl_encode_memory_barrier(struct virgl_context
*ctx
,
277 int virgl_encode_launch_grid(struct virgl_context
*ctx
,
278 const struct pipe_grid_info
*grid_info
);
279 int virgl_encode_texture_barrier(struct virgl_context
*ctx
,
282 int virgl_encode_host_debug_flagstring(struct virgl_context
*ctx
,
283 const char *envname
);
285 int virgl_encode_get_query_result_qbo(struct virgl_context
*ctx
,
287 struct virgl_resource
*res
, boolean wait
,
288 uint32_t result_type
,
292 void virgl_encode_transfer(struct virgl_screen
*vs
, struct virgl_cmd_buf
*buf
,
293 struct virgl_transfer
*trans
, uint32_t direction
);
295 void virgl_encode_end_transfers(struct virgl_cmd_buf
*buf
);