virgl: modify how we handle GL_MAP_FLUSH_EXPLICIT_BIT
[mesa.git] / src / gallium / drivers / virgl / virgl_resource.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
24 #ifndef VIRGL_RESOURCE_H
25 #define VIRGL_RESOURCE_H
26
27 #include "util/u_resource.h"
28 #include "util/u_range.h"
29 #include "util/list.h"
30 #include "util/u_transfer.h"
31
32 #include "virgl_hw.h"
33 #define VR_MAX_TEXTURE_2D_LEVELS 15
34
35 struct winsys_handle;
36 struct virgl_screen;
37 struct virgl_context;
38
39 struct virgl_resource_metadata
40 {
41 unsigned long level_offset[VR_MAX_TEXTURE_2D_LEVELS];
42 unsigned stride[VR_MAX_TEXTURE_2D_LEVELS];
43 unsigned layer_stride[VR_MAX_TEXTURE_2D_LEVELS];
44 uint32_t total_size;
45 };
46
47 struct virgl_resource {
48 struct u_resource u;
49 struct virgl_hw_res *hw_res;
50 boolean clean;
51 };
52
53 struct virgl_buffer {
54 struct virgl_resource base;
55 struct virgl_resource_metadata metadata;
56 };
57
58 struct virgl_texture {
59 struct virgl_resource base;
60 struct virgl_resource_metadata metadata;
61 };
62
63 struct virgl_transfer {
64 struct pipe_transfer base;
65 uint32_t offset, l_stride;
66 struct util_range range;
67 struct virgl_resource *resolve_tmp;
68 };
69
70 void virgl_resource_destroy(struct pipe_screen *screen,
71 struct pipe_resource *resource);
72
73 void virgl_init_screen_resource_functions(struct pipe_screen *screen);
74
75 void virgl_init_context_resource_functions(struct pipe_context *ctx);
76
77 struct pipe_resource *virgl_texture_create(struct virgl_screen *vs,
78 const struct pipe_resource *templ);
79
80 struct pipe_resource *virgl_texture_from_handle(struct virgl_screen *vs,
81 const struct pipe_resource *templ,
82 struct winsys_handle *whandle);
83
84 static inline struct virgl_resource *virgl_resource(struct pipe_resource *r)
85 {
86 return (struct virgl_resource *)r;
87 }
88
89 static inline struct virgl_buffer *virgl_buffer(struct pipe_resource *r)
90 {
91 return (struct virgl_buffer *)r;
92 }
93
94 static inline struct virgl_texture *virgl_texture(struct pipe_resource *r)
95 {
96 return (struct virgl_texture *)r;
97 }
98
99 static inline struct virgl_transfer *virgl_transfer(struct pipe_transfer *trans)
100 {
101 return (struct virgl_transfer *)trans;
102 }
103
104 struct pipe_resource *virgl_buffer_create(struct virgl_screen *vs,
105 const struct pipe_resource *templ);
106
107 static inline unsigned pipe_to_virgl_bind(unsigned pbind)
108 {
109 unsigned outbind = 0;
110 if (pbind & PIPE_BIND_DEPTH_STENCIL)
111 outbind |= VIRGL_BIND_DEPTH_STENCIL;
112 if (pbind & PIPE_BIND_RENDER_TARGET)
113 outbind |= VIRGL_BIND_RENDER_TARGET;
114 if (pbind & PIPE_BIND_SAMPLER_VIEW)
115 outbind |= VIRGL_BIND_SAMPLER_VIEW;
116 if (pbind & PIPE_BIND_VERTEX_BUFFER)
117 outbind |= VIRGL_BIND_VERTEX_BUFFER;
118 if (pbind & PIPE_BIND_INDEX_BUFFER)
119 outbind |= VIRGL_BIND_INDEX_BUFFER;
120 if (pbind & PIPE_BIND_CONSTANT_BUFFER)
121 outbind |= VIRGL_BIND_CONSTANT_BUFFER;
122 if (pbind & PIPE_BIND_DISPLAY_TARGET)
123 outbind |= VIRGL_BIND_DISPLAY_TARGET;
124 if (pbind & PIPE_BIND_STREAM_OUTPUT)
125 outbind |= VIRGL_BIND_STREAM_OUTPUT;
126 if (pbind & PIPE_BIND_CURSOR)
127 outbind |= VIRGL_BIND_CURSOR;
128 if (pbind & PIPE_BIND_CUSTOM)
129 outbind |= VIRGL_BIND_CUSTOM;
130 if (pbind & PIPE_BIND_SCANOUT)
131 outbind |= VIRGL_BIND_SCANOUT;
132 if (pbind & PIPE_BIND_SHADER_BUFFER)
133 outbind |= VIRGL_BIND_SHADER_BUFFER;
134 return outbind;
135 }
136
137 bool virgl_res_needs_flush_wait(struct virgl_context *vctx,
138 struct virgl_resource *res,
139 unsigned usage);
140 bool virgl_res_needs_readback(struct virgl_context *vctx,
141 struct virgl_resource *res,
142 unsigned usage);
143
144 void virgl_resource_layout(struct pipe_resource *pt,
145 struct virgl_resource_metadata *metadata);
146
147 struct virgl_transfer *
148 virgl_resource_create_transfer(struct pipe_context *ctx,
149 struct pipe_resource *pres,
150 const struct virgl_resource_metadata *metadata,
151 unsigned level, unsigned usage,
152 const struct pipe_box *box);
153
154 void virgl_resource_destroy_transfer(struct virgl_context *vctx,
155 struct virgl_transfer *trans);
156
157 #endif