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