1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
/*
* Copyright 2014, 2015 Red Hat.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* on the rights to use, copy, modify, merge, publish, distribute, sub
* license, and/or sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef VIRGL_ENCODE_H
#define VIRGL_ENCODE_H
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
#include "virgl_winsys.h"
#include "virgl_protocol.h"
struct tgsi_token;
struct virgl_context;
struct virgl_resource;
struct virgl_screen;
struct virgl_transfer;
struct virgl_sampler_view;
struct virgl_surface {
struct pipe_surface base;
uint32_t handle;
};
struct virgl_indexbuf {
unsigned offset;
unsigned index_size; /**< size of an index, in bytes */
struct pipe_resource *buffer; /**< the actual buffer */
const void *user_buffer; /**< pointer to a user buffer if buffer == NULL */
};
static inline struct virgl_surface *virgl_surface(struct pipe_surface *surf)
{
return (struct virgl_surface *)surf;
}
static inline void virgl_encoder_write_dword(struct virgl_cmd_buf *state,
uint32_t dword)
{
state->buf[state->cdw++] = dword;
}
static inline void virgl_encoder_write_qword(struct virgl_cmd_buf *state,
uint64_t qword)
{
memcpy(state->buf + state->cdw, &qword, sizeof(uint64_t));
state->cdw += 2;
}
static inline void virgl_encoder_write_block(struct virgl_cmd_buf *state,
const uint8_t *ptr, uint32_t len)
{
int x;
memcpy(state->buf + state->cdw, ptr, len);
x = (len % 4);
if (x) {
uint8_t *mp = (uint8_t *)(state->buf + state->cdw);
mp += len;
memset(mp, 0, x);
}
state->cdw += (len + 3) / 4;
}
extern int virgl_encode_blend_state(struct virgl_context *ctx,
uint32_t handle,
const struct pipe_blend_state *blend_state);
extern int virgl_encode_rasterizer_state(struct virgl_context *ctx,
uint32_t handle,
const struct pipe_rasterizer_state *state);
extern int virgl_encode_shader_state(struct virgl_context *ctx,
uint32_t handle,
uint32_t type,
const struct pipe_stream_output_info *so_info,
uint32_t cs_req_local_mem,
const struct tgsi_token *tokens);
int virgl_encode_stream_output_info(struct virgl_context *ctx,
uint32_t handle,
uint32_t type,
const struct pipe_shader_state *shader);
int virgl_encoder_set_so_targets(struct virgl_context *ctx,
unsigned num_targets,
struct pipe_stream_output_target **targets,
unsigned append_bitmask);
int virgl_encoder_create_so_target(struct virgl_context *ctx,
uint32_t handle,
struct virgl_resource *res,
unsigned buffer_offset,
unsigned buffer_size);
int virgl_encode_clear(struct virgl_context *ctx,
unsigned buffers,
const union pipe_color_union *color,
double depth, unsigned stencil);
int virgl_encode_clear_texture(struct virgl_context *ctx,
struct virgl_resource *res,
unsigned int level,
const struct pipe_box *box,
const void *data);
int virgl_encode_bind_object(struct virgl_context *ctx,
uint32_t handle, uint32_t object);
int virgl_encode_delete_object(struct virgl_context *ctx,
uint32_t handle, uint32_t object);
int virgl_encoder_set_framebuffer_state(struct virgl_context *ctx,
const struct pipe_framebuffer_state *state);
int virgl_encoder_set_viewport_states(struct virgl_context *ctx,
int start_slot,
int num_viewports,
const struct pipe_viewport_state *states);
int virgl_encoder_draw_vbo(struct virgl_context *ctx,
const struct pipe_draw_info *info);
int virgl_encoder_create_surface(struct virgl_context *ctx,
uint32_t handle,
struct virgl_resource *res,
const struct pipe_surface *templat);
int virgl_encoder_flush_frontbuffer(struct virgl_context *ctx,
struct virgl_resource *res);
int virgl_encoder_create_vertex_elements(struct virgl_context *ctx,
uint32_t handle,
unsigned num_elements,
const struct pipe_vertex_element *element);
int virgl_encoder_set_vertex_buffers(struct virgl_context *ctx,
unsigned num_buffers,
const struct pipe_vertex_buffer *buffers);
int virgl_encoder_inline_write(struct virgl_context *ctx,
struct virgl_resource *res,
unsigned level, unsigned usage,
const struct pipe_box *box,
const void *data, unsigned stride,
unsigned layer_stride);
int virgl_encode_sampler_state(struct virgl_context *ctx,
uint32_t handle,
const struct pipe_sampler_state *state);
int virgl_encode_sampler_view(struct virgl_context *ctx,
uint32_t handle,
struct virgl_resource *res,
const struct pipe_sampler_view *state);
int virgl_encode_set_sampler_views(struct virgl_context *ctx,
uint32_t shader_type,
uint32_t start_slot,
uint32_t num_views,
struct virgl_sampler_view **views);
int virgl_encode_bind_sampler_states(struct virgl_context *ctx,
uint32_t shader_type,
uint32_t start_slot,
uint32_t num_handles,
uint32_t *handles);
int virgl_encoder_set_index_buffer(struct virgl_context *ctx,
const struct virgl_indexbuf *ib);
uint32_t virgl_object_assign_handle(void);
int virgl_encoder_write_constant_buffer(struct virgl_context *ctx,
uint32_t shader,
uint32_t index,
uint32_t size,
const void *data);
int virgl_encoder_set_uniform_buffer(struct virgl_context *ctx,
uint32_t shader,
uint32_t index,
uint32_t offset,
uint32_t length,
struct virgl_resource *res);
int virgl_encode_dsa_state(struct virgl_context *ctx,
uint32_t handle,
const struct pipe_depth_stencil_alpha_state *dsa_state);
int virgl_encoder_set_stencil_ref(struct virgl_context *ctx,
const struct pipe_stencil_ref *ref);
int virgl_encoder_set_blend_color(struct virgl_context *ctx,
const struct pipe_blend_color *color);
int virgl_encoder_set_scissor_state(struct virgl_context *ctx,
unsigned start_slot,
int num_scissors,
const struct pipe_scissor_state *ss);
void virgl_encoder_set_polygon_stipple(struct virgl_context *ctx,
const struct pipe_poly_stipple *ps);
void virgl_encoder_set_sample_mask(struct virgl_context *ctx,
unsigned sample_mask);
void virgl_encoder_set_min_samples(struct virgl_context *ctx,
unsigned min_samples);
void virgl_encoder_set_clip_state(struct virgl_context *ctx,
const struct pipe_clip_state *clip);
int virgl_encode_resource_copy_region(struct virgl_context *ctx,
struct virgl_resource *dst_res,
unsigned dst_level,
unsigned dstx, unsigned dsty, unsigned dstz,
struct virgl_resource *src_res,
unsigned src_level,
const struct pipe_box *src_box);
int virgl_encode_blit(struct virgl_context *ctx,
struct virgl_resource *dst_res,
struct virgl_resource *src_res,
const struct pipe_blit_info *blit);
int virgl_encoder_create_query(struct virgl_context *ctx,
uint32_t handle,
uint query_type,
uint query_index,
struct virgl_resource *res,
uint32_t offset);
int virgl_encoder_begin_query(struct virgl_context *ctx,
uint32_t handle);
int virgl_encoder_end_query(struct virgl_context *ctx,
uint32_t handle);
int virgl_encoder_get_query_result(struct virgl_context *ctx,
uint32_t handle, boolean wait);
int virgl_encoder_render_condition(struct virgl_context *ctx,
uint32_t handle, boolean condition,
enum pipe_render_cond_flag mode);
int virgl_encoder_set_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
int virgl_encoder_create_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
int virgl_encoder_destroy_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
int virgl_encode_bind_shader(struct virgl_context *ctx,
uint32_t handle, uint32_t type);
int virgl_encode_set_tess_state(struct virgl_context *ctx,
const float outer[4],
const float inner[2]);
int virgl_encode_set_shader_buffers(struct virgl_context *ctx,
enum pipe_shader_type shader,
unsigned start_slot, unsigned count,
const struct pipe_shader_buffer *buffers);
int virgl_encode_set_shader_images(struct virgl_context *ctx,
enum pipe_shader_type shader,
unsigned start_slot, unsigned count,
const struct pipe_image_view *images);
int virgl_encode_set_hw_atomic_buffers(struct virgl_context *ctx,
unsigned start_slot, unsigned count,
const struct pipe_shader_buffer *buffers);
int virgl_encode_memory_barrier(struct virgl_context *ctx,
unsigned flags);
int virgl_encode_launch_grid(struct virgl_context *ctx,
const struct pipe_grid_info *grid_info);
int virgl_encode_texture_barrier(struct virgl_context *ctx,
unsigned flags);
int virgl_encode_host_debug_flagstring(struct virgl_context *ctx,
const char *envname);
int virgl_encode_get_query_result_qbo(struct virgl_context *ctx,
uint32_t handle,
struct virgl_resource *res, boolean wait,
uint32_t result_type,
uint32_t offset,
uint32_t index);
void virgl_encode_transfer(struct virgl_screen *vs, struct virgl_cmd_buf *buf,
struct virgl_transfer *trans, uint32_t direction);
void virgl_encode_copy_transfer(struct virgl_context *ctx,
struct virgl_transfer *trans);
void virgl_encode_end_transfers(struct virgl_cmd_buf *buf);
int virgl_encode_tweak(struct virgl_context *ctx, enum vrend_tweak_type tweak, uint32_t value);
enum virgl_formats pipe_to_virgl_format(enum pipe_format format);
#endif
|