virgl: modify how we handle GL_MAP_FLUSH_EXPLICIT_BIT
[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 struct pipe_screen;
32 struct tgsi_token;
33 struct u_upload_mgr;
34 struct virgl_cmd_buf;
35 struct virgl_vertex_elements_state;
36
37 struct virgl_sampler_view {
38 struct pipe_sampler_view base;
39 uint32_t handle;
40 };
41
42 struct virgl_so_target {
43 struct pipe_stream_output_target base;
44 uint32_t handle;
45 };
46
47 struct virgl_textures_info {
48 struct virgl_sampler_view *views[16];
49 uint32_t enabled_mask;
50 };
51
52 struct virgl_context {
53 struct pipe_context base;
54 struct virgl_cmd_buf *cbuf;
55
56 struct virgl_textures_info samplers[PIPE_SHADER_TYPES];
57 struct virgl_vertex_elements_state *vertex_elements;
58
59 struct pipe_framebuffer_state framebuffer;
60
61 struct slab_child_pool transfer_pool;
62
63 struct u_upload_mgr *uploader;
64
65 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
66 unsigned num_vertex_buffers;
67 boolean vertex_array_dirty;
68
69 struct virgl_so_target so_targets[PIPE_MAX_SO_BUFFERS];
70 unsigned num_so_targets;
71
72 struct pipe_resource *ubos[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
73
74 struct pipe_resource *ssbos[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
75 struct pipe_resource *images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
76 int num_transfers;
77 int num_draws;
78
79 struct pipe_resource *atomic_buffers[PIPE_MAX_HW_ATOMIC_BUFFERS];
80
81 struct primconvert_context *primconvert;
82 uint32_t hw_sub_ctx_id;
83 };
84
85 static inline struct virgl_sampler_view *
86 virgl_sampler_view(struct pipe_sampler_view *view)
87 {
88 return (struct virgl_sampler_view *)view;
89 };
90
91 static inline struct virgl_so_target *
92 virgl_so_target(struct pipe_stream_output_target *target)
93 {
94 return (struct virgl_so_target *)target;
95 }
96
97 static inline struct virgl_context *virgl_context(struct pipe_context *ctx)
98 {
99 return (struct virgl_context *)ctx;
100 }
101
102 struct pipe_context *virgl_context_create(struct pipe_screen *pscreen,
103 void *priv, unsigned flags);
104
105 void virgl_init_blit_functions(struct virgl_context *vctx);
106 void virgl_init_query_functions(struct virgl_context *vctx);
107 void virgl_init_so_functions(struct virgl_context *vctx);
108
109 void virgl_transfer_inline_write(struct pipe_context *ctx,
110 struct pipe_resource *res,
111 unsigned level,
112 unsigned usage,
113 const struct pipe_box *box,
114 const void *data,
115 unsigned stride,
116 unsigned layer_stride);
117
118 struct tgsi_token *virgl_tgsi_transform(struct virgl_context *vctx, const struct tgsi_token *tokens_in);
119
120 #endif