virgl: handle DONT_BLOCK and MAP_DIRECTLY
[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 #include "virgl_screen.h"
34 #define VR_MAX_TEXTURE_2D_LEVELS 15
35
36 struct winsys_handle;
37 struct virgl_screen;
38 struct virgl_context;
39
40 struct virgl_resource_metadata
41 {
42 unsigned long level_offset[VR_MAX_TEXTURE_2D_LEVELS];
43 unsigned stride[VR_MAX_TEXTURE_2D_LEVELS];
44 unsigned layer_stride[VR_MAX_TEXTURE_2D_LEVELS];
45 uint32_t total_size;
46 };
47
48 struct virgl_resource {
49 struct u_resource u;
50 uint16_t clean_mask;
51 struct virgl_hw_res *hw_res;
52 struct virgl_resource_metadata metadata;
53 };
54
55 enum virgl_transfer_map_type {
56 VIRGL_TRANSFER_MAP_ERROR = -1,
57 VIRGL_TRANSFER_MAP_HW_RES,
58 };
59
60 struct virgl_transfer {
61 struct pipe_transfer base;
62 uint32_t offset, l_stride;
63 struct util_range range;
64 struct list_head queue_link;
65 struct pipe_transfer *resolve_transfer;
66 void *hw_res_map;
67 };
68
69 void virgl_resource_destroy(struct pipe_screen *screen,
70 struct pipe_resource *resource);
71
72 void virgl_init_screen_resource_functions(struct pipe_screen *screen);
73
74 void virgl_init_context_resource_functions(struct pipe_context *ctx);
75
76 void virgl_texture_init(struct virgl_resource *res);
77
78 static inline struct virgl_resource *virgl_resource(struct pipe_resource *r)
79 {
80 return (struct virgl_resource *)r;
81 }
82
83 static inline struct virgl_transfer *virgl_transfer(struct pipe_transfer *trans)
84 {
85 return (struct virgl_transfer *)trans;
86 }
87
88 void virgl_buffer_init(struct virgl_resource *res);
89
90 static inline unsigned pipe_to_virgl_bind(const struct virgl_screen *vs, unsigned pbind)
91 {
92 unsigned outbind = 0;
93 if (pbind & PIPE_BIND_DEPTH_STENCIL)
94 outbind |= VIRGL_BIND_DEPTH_STENCIL;
95 if (pbind & PIPE_BIND_RENDER_TARGET)
96 outbind |= VIRGL_BIND_RENDER_TARGET;
97 if (pbind & PIPE_BIND_SAMPLER_VIEW)
98 outbind |= VIRGL_BIND_SAMPLER_VIEW;
99 if (pbind & PIPE_BIND_VERTEX_BUFFER)
100 outbind |= VIRGL_BIND_VERTEX_BUFFER;
101 if (pbind & PIPE_BIND_INDEX_BUFFER)
102 outbind |= VIRGL_BIND_INDEX_BUFFER;
103 if (pbind & PIPE_BIND_CONSTANT_BUFFER)
104 outbind |= VIRGL_BIND_CONSTANT_BUFFER;
105 if (pbind & PIPE_BIND_DISPLAY_TARGET)
106 outbind |= VIRGL_BIND_DISPLAY_TARGET;
107 if (pbind & PIPE_BIND_STREAM_OUTPUT)
108 outbind |= VIRGL_BIND_STREAM_OUTPUT;
109 if (pbind & PIPE_BIND_CURSOR)
110 outbind |= VIRGL_BIND_CURSOR;
111 if (pbind & PIPE_BIND_CUSTOM)
112 outbind |= VIRGL_BIND_CUSTOM;
113 if (pbind & PIPE_BIND_SCANOUT)
114 outbind |= VIRGL_BIND_SCANOUT;
115 if (pbind & PIPE_BIND_SHADER_BUFFER)
116 outbind |= VIRGL_BIND_SHADER_BUFFER;
117 if (pbind & PIPE_BIND_QUERY_BUFFER)
118 outbind |= VIRGL_BIND_QUERY_BUFFER;
119 if (pbind & PIPE_BIND_COMMAND_ARGS_BUFFER)
120 if (vs->caps.caps.v2.capability_bits & VIRGL_CAP_BIND_COMMAND_ARGS)
121 outbind |= VIRGL_BIND_COMMAND_ARGS;
122 return outbind;
123 }
124
125 enum virgl_transfer_map_type
126 virgl_resource_transfer_prepare(struct virgl_context *vctx,
127 struct virgl_transfer *xfer);
128
129 void virgl_resource_layout(struct pipe_resource *pt,
130 struct virgl_resource_metadata *metadata);
131
132 struct virgl_transfer *
133 virgl_resource_create_transfer(struct slab_child_pool *pool,
134 struct pipe_resource *pres,
135 const struct virgl_resource_metadata *metadata,
136 unsigned level, unsigned usage,
137 const struct pipe_box *box);
138
139 void virgl_resource_destroy_transfer(struct slab_child_pool *pool,
140 struct virgl_transfer *trans);
141
142 void virgl_resource_destroy(struct pipe_screen *screen,
143 struct pipe_resource *resource);
144
145 boolean virgl_resource_get_handle(struct pipe_screen *screen,
146 struct pipe_resource *resource,
147 struct winsys_handle *whandle);
148
149 void virgl_resource_dirty(struct virgl_resource *res, uint32_t level);
150
151 #endif