softpipe: add support for vertex streams (v2)
[mesa.git] / src / gallium / drivers / virgl / virgl_context.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_CONTEXT_H
24 #define VIRGL_CONTEXT_H
25
26 #include "pipe/p_state.h"
27 #include "pipe/p_context.h"
28 #include "util/slab.h"
29 #include "util/list.h"
30
31 #include "virgl_transfer_queue.h"
32
33 struct pipe_screen;
34 struct tgsi_token;
35 struct u_upload_mgr;
36 struct virgl_cmd_buf;
37 struct virgl_vertex_elements_state;
38
39 struct virgl_sampler_view {
40 struct pipe_sampler_view base;
41 uint32_t handle;
42 };
43
44 struct virgl_so_target {
45 struct pipe_stream_output_target base;
46 uint32_t handle;
47 };
48
49 struct virgl_textures_info {
50 struct virgl_sampler_view *views[16];
51 uint32_t enabled_mask;
52 };
53
54 struct virgl_rasterizer_state {
55 struct pipe_rasterizer_state rs;
56 uint32_t handle;
57 };
58
59 struct virgl_context {
60 struct pipe_context base;
61 struct virgl_cmd_buf *cbuf;
62
63 struct virgl_textures_info samplers[PIPE_SHADER_TYPES];
64 struct virgl_vertex_elements_state *vertex_elements;
65
66 struct pipe_framebuffer_state framebuffer;
67
68 struct slab_child_pool transfer_pool;
69 struct virgl_transfer_queue queue;
70 struct u_upload_mgr *uploader;
71 bool encoded_transfers;
72
73 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
74 unsigned num_vertex_buffers;
75 boolean vertex_array_dirty;
76
77 struct virgl_rasterizer_state rs_state;
78 struct virgl_so_target so_targets[PIPE_MAX_SO_BUFFERS];
79 unsigned num_so_targets;
80
81 struct pipe_resource *ubos[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
82
83 struct pipe_resource *ssbos[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
84 struct pipe_resource *images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
85 uint32_t num_transfers, num_draws, num_compute;
86
87 struct pipe_resource *atomic_buffers[PIPE_MAX_HW_ATOMIC_BUFFERS];
88
89 struct primconvert_context *primconvert;
90 uint32_t hw_sub_ctx_id;
91 };
92
93 static inline struct virgl_sampler_view *
94 virgl_sampler_view(struct pipe_sampler_view *view)
95 {
96 return (struct virgl_sampler_view *)view;
97 };
98
99 static inline struct virgl_so_target *
100 virgl_so_target(struct pipe_stream_output_target *target)
101 {
102 return (struct virgl_so_target *)target;
103 }
104
105 static inline struct virgl_context *virgl_context(struct pipe_context *ctx)
106 {
107 return (struct virgl_context *)ctx;
108 }
109
110 struct pipe_context *virgl_context_create(struct pipe_screen *pscreen,
111 void *priv, unsigned flags);
112
113 void virgl_init_blit_functions(struct virgl_context *vctx);
114 void virgl_init_query_functions(struct virgl_context *vctx);
115 void virgl_init_so_functions(struct virgl_context *vctx);
116
117 void virgl_transfer_inline_write(struct pipe_context *ctx,
118 struct pipe_resource *res,
119 unsigned level,
120 unsigned usage,
121 const struct pipe_box *box,
122 const void *data,
123 unsigned stride,
124 unsigned layer_stride);
125
126 struct tgsi_token *virgl_tgsi_transform(struct virgl_context *vctx, const struct tgsi_token *tokens_in);
127
128 #endif